summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/shm_ap_rbuff.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/lib/shm_ap_rbuff.c b/src/lib/shm_ap_rbuff.c
index 0a41dfb3..34583d8e 100644
--- a/src/lib/shm_ap_rbuff.c
+++ b/src/lib/shm_ap_rbuff.c
@@ -244,17 +244,20 @@ int shm_ap_rbuff_write(struct shm_ap_rbuff * rb, struct rb_entry * e)
}
struct rb_entry * shm_ap_rbuff_read(struct shm_ap_rbuff * rb)
{
- struct rb_entry * e = malloc(sizeof(*e));
- if (e == NULL)
- return NULL;
+ struct rb_entry * e = NULL;
if (rb == NULL)
return NULL;
+ e = malloc(sizeof(*e));
+ if (e == NULL)
+ return NULL;
+
pthread_mutex_lock(rb->shm_mutex);
if (shm_rbuff_used(rb) == 0) {
pthread_mutex_unlock(rb->shm_mutex);
+ free(e);
return NULL;
}