summaryrefslogtreecommitdiff
path: root/src/lib/shm_ap_rbuff.c
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2016-05-14 11:35:55 +0200
committerdimitri staessens <[email protected]>2016-05-14 11:35:55 +0200
commit182e493a5668b66d3017d92130b5fb31d325796d (patch)
tree94494b4589c1ae41b913976566812eaeb8b3e068 /src/lib/shm_ap_rbuff.c
parentfe4eb1fe61042a08686be54a37f72de72bef70f8 (diff)
downloadouroboros-182e493a5668b66d3017d92130b5fb31d325796d.tar.gz
ouroboros-182e493a5668b66d3017d92130b5fb31d325796d.zip
lib: shm_ap_rbuff: removed bad memory allocation
moved a malloc so there is no malloc/free when there is no data to be read from the shm_ap_rbuff.
Diffstat (limited to 'src/lib/shm_ap_rbuff.c')
-rw-r--r--src/lib/shm_ap_rbuff.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/lib/shm_ap_rbuff.c b/src/lib/shm_ap_rbuff.c
index 6c977cbb..6c04ccc5 100644
--- a/src/lib/shm_ap_rbuff.c
+++ b/src/lib/shm_ap_rbuff.c
@@ -245,18 +245,17 @@ struct rb_entry * shm_ap_rbuff_read(struct shm_ap_rbuff * rb)
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;
}
+ e = malloc(sizeof(*e));
+ if (e == NULL)
+ return NULL;
+
*e = *(rb->shm_base + *rb->ptr_tail);
*rb->ptr_tail = (*rb->ptr_tail + 1) & (SHM_RBUFF_SIZE -1);