comparison src/thread/irix/SDL_syssem.c @ 1499:ad887c988713

Fixed bug #150 memory leak in SDL_thread.c
author Sam Lantinga <slouken@libsdl.org>
date Sun, 12 Mar 2006 01:18:29 +0000
parents d910939febfa
children 782fd950bd46 c121d94672cb a1b03ba2fcd0
comparison
equal deleted inserted replaced
1498:3968f7cba10c 1499:ad887c988713
65 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) 65 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
66 { 66 {
67 extern int _creating_thread_lock; /* SDL_threads.c */ 67 extern int _creating_thread_lock; /* SDL_threads.c */
68 SDL_sem *sem; 68 SDL_sem *sem;
69 union semun init; 69 union semun init;
70 key_t key;
71 70
72 sem = (SDL_sem *)SDL_malloc(sizeof(*sem)); 71 sem = (SDL_sem *)SDL_malloc(sizeof(*sem));
73 if ( sem == NULL ) { 72 if ( sem == NULL ) {
74 SDL_OutOfMemory(); 73 SDL_OutOfMemory();
75 return(NULL); 74 return(NULL);
76 } 75 }
77 /* This flag is true if we are creating the thread manager sem, 76 sem->id = semget(IPC_PRIVATE, 1, (0600|IPC_CREAT));
78 which is never freed. This allows us to reuse the same sem.
79 */
80 if ( _creating_thread_lock ) {
81 key = 'S'+'D'+'L';
82 } else {
83 key = IPC_PRIVATE;
84 }
85 /* Keep trying to create sem while we don't own the requested key */
86 do {
87 if ( key != IPC_PRIVATE ) {
88 ++key;
89 }
90 sem->id = semget(key, 1, (0600|IPC_CREAT));
91 } while ((sem->id < 0) && (key != IPC_PRIVATE) && (errno == EACCES));
92
93 /* Report the error if we eventually failed */
94 if ( sem->id < 0 ) { 77 if ( sem->id < 0 ) {
95 SDL_SetError("Couldn't create semaphore"); 78 SDL_SetError("Couldn't create semaphore");
96 SDL_free(sem); 79 SDL_free(sem);
97 return(NULL); 80 return(NULL);
98 } 81 }