From dff3ff4afe5723bd4fa2c8c69f52d357a265d037 Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Wed, 8 Feb 2012 20:50:52 +1100 Subject: [PATCH] RB: Fix potential mem leak Signed-off-by: Angus Salkeld --- lib/ringbuffer.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ringbuffer.c b/lib/ringbuffer.c index e76abcf..cc7d8b1 100644 --- a/lib/ringbuffer.c +++ b/lib/ringbuffer.c @@ -652,9 +652,13 @@ qb_rb_create_from_file(int32_t fd, uint32_t flags) size_t total_read = 0; uint32_t read_pt; uint32_t write_pt; - qb_ringbuffer_t *rb = calloc(1, sizeof(qb_ringbuffer_t)); + qb_ringbuffer_t *rb; - if (rb == NULL || fd < 0) { + if (fd < 0) { + return NULL; + } + rb = calloc(1, sizeof(qb_ringbuffer_t)); + if (rb == NULL) { return NULL; } rb->shared_hdr = calloc(1, sizeof(struct qb_ringbuffer_shared_s));