Fixing minor exception checks
[ric-plt/lib/rmr.git] / src / rmr / common / src / ring_static.c
index b54d815..8e565fa 100644 (file)
@@ -85,12 +85,12 @@ static void* uta_mk_ring( int size ) {
        }
 
        r->nelements = size;            // because we always have an empty element when full
-       if( (r->data = (void **) malloc( sizeof( void** ) * (r->nelements + 1) )) == NULL ) {
+       if( (r->data = (void **) malloc( sizeof( void* ) * (r->nelements + 1) )) == NULL ) {
                free( r );
                return NULL;
        }
 
-       memset( r->data, 0, sizeof( void** ) * r->nelements );
+       memset( r->data, 0, sizeof( void* ) * r->nelements );
        r->pfd = eventfd( 0, EFD_SEMAPHORE | EFD_NONBLOCK );            // in semaphore mode counter is maintained with each insert/extract
        return (void *) r;
 }
@@ -148,7 +148,15 @@ static void uta_ring_free( void* vr ) {
        if( (r = (ring_t*) vr) == NULL ) {
                return;
        }
-
+       if( r->data ){
+               free( r->data );
+       }
+       if( r->rgate ){
+               free( r->rgate );
+       }
+       if( r->wgate ){
+               free( r->wgate );
+       }
        free( r );
 }
 
@@ -183,6 +191,7 @@ static inline void* uta_ring_extract( void* vr ) {
        if( r->rgate != NULL ) {                                                // if lock exists we must honour it
                pthread_mutex_lock( r->rgate );
                if( r->tail == r->head ) {                                      // ensure ring didn't go empty while waiting
+                       pthread_mutex_unlock( r->rgate );
                        return NULL;
                }
        }