Bug 214396 - emulators/virtualbox-ose-additions Minimalist program crashes after end main() execution.
Summary: emulators/virtualbox-ose-additions Minimalist program crashes after end main(...
Status: Closed Not A Bug
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Virtualbox Team (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-10 17:20 UTC by Otacílio de Araújo Ramos Neto
Modified: 2017-07-05 13:27 UTC (History)
0 users

See Also:
bugzilla: maintainer-feedback? (vbox)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Otacílio de Araújo Ramos Neto 2016-11-10 17:20:48 UTC
This small program crashes when executing the return 0; line.

#include <stdio.h>
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <GL/glext.h>

int main(int argc, char **argv) {

    glutInit(&argc, argv);
    glutCreateWindow("GLUT");
    glewInit();

    printf("OpenGL version supported by this platform (%s): \n", glGetString(GL_VERSION));

    fprintf(stdout, "Exiting...\n"); 
    fflush(stdout);

    return 0;
}


To reproduce you must install virtualbox-ose-additions with opengl enabled and compile (cc -I/usr/local/include -L/usr/local/lib -o testegl testegl.c -lGL -lGLEW -lGLU   -lglut) and run this program.

After debugging gdb say that the exception is raised on line 679 of file /usr/ports/emulators/virtualbox-ose-additions/work/VirtualBox-5.1.8/src/VBox/GuestHost/OpenGL/util/hash.c

void *crHashtableSearch( const CRHashTable *h, unsigned long key )
{
    unsigned int index = crHash( key );
    CRHashNode *temp;
#ifdef CHROMIUM_THREADSAFE
bug is here  =======>  crLockMutex((CRmutex *)&h->mutex);
#endif
    for ( temp = h->buckets[index]; temp; temp = temp->next )
    {
        if ( temp->key == key )
            break;
    }
#ifdef CHROMIUM_THREADSAFE
    crUnlockMutex((CRmutex *)&h->mutex);
#endif
    if ( !temp )
    {
        return NULL;
    }
    return temp->data;
}
Comment 1 Otacílio de Araújo Ramos Neto 2016-11-10 17:42:23 UTC
(gdb) backtrace
#0  check_and_init_mutex (mutex=0x20c8, m=0x7fffffffe650) at /usr/src/lib/libthr/thread/thr_mutex.c:588
#1  0x0000000802923506 in __pthread_mutex_lock (mutex=0x20c8) at /usr/src/lib/libthr/thread/thr_mutex.c:743
#2  0x0000000801e531f1 in crHashtableSearch (h=0x0, key=56623106) at /usr/ports/emulators/virtualbox-ose-additions/work/VirtualBox-5.1.8/src/VBox/GuestHost/OpenGL/util/hash.c:679
#3  0x000000080088f1cb in glXMakeCurrent (dpy=0x80481f000, drawable=56623106, ctx=0x1f4) at /usr/ports/emulators/virtualbox-ose-additions/work/VirtualBox-5.1.8/src/VBox/Additions/common/crOpenGL/glx.c:694
#4  0x00000008010ce5be in fgSetWindow () from /usr/local/lib/libglut.so.3
#5  0x00000008010cc44c in fgDestroyWindow () from /usr/local/lib/libglut.so.3
#6  0x00000008010cc895 in fgDestroyStructure () from /usr/local/lib/libglut.so.3
#7  0x00000008010c9841 in fgDeinitialize () from /usr/local/lib/libglut.so.3
#8  0x0000000801b9add6 in __cxa_finalize (dso=<value optimized out>) at /usr/src/lib/libc/stdlib/atexit.c:237
#9  0x0000000801b2a141 in exit (status=0) at /usr/src/lib/libc/stdlib/exit.c:72
#10 0x0000000000400976 in _start ()
#11 0x0000000800622000 in ?? ()
#12 0x0000000000000000 in ?? ()
Comment 2 Otacílio de Araújo Ramos Neto 2016-11-21 12:01:28 UTC
Oracle guy confirms that this occurs on Linux also.
Comment 3 Otacílio de Araújo Ramos Neto 2017-06-30 14:22:28 UTC
This version of the program do not shows the bug. Looks related with a race condition when a call to glutDestroyWindow is missing.

#include <stdio.h>
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <GL/glext.h>

int main(int argc, char **argv) {

        int win;
        glutInit(&argc, argv);
        win = glutCreateWindow("GLUT");
        glewInit();

        printf("OpenGL version supported by this platform (%s): \n", glGetString(GL_VERSION));

        glutDestroyWindow(win);
        fprintf(stdout, "Exiting...\n");
        fflush(stdout);

        return 0;
}
Comment 4 Otacílio de Araújo Ramos Neto 2017-07-05 13:27:04 UTC
I think that this is related with application bad code because if add glutDestroyWindow to close the window before exit the program finishes fine.