From a04843bc9e1aaf35c477ade632ec42bee5c84796 Mon Sep 17 00:00:00 2001 From: Hardening Date: Wed, 21 May 2014 18:32:59 +0200 Subject: [PATCH] Fix some corner cases in ringbuffer and make unitary test have no leak --- libfreerdp/utils/ringbuffer.c | 2 ++ libfreerdp/utils/test/TestRingBuffer.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/libfreerdp/utils/ringbuffer.c b/libfreerdp/utils/ringbuffer.c index 493445705..95b5652fd 100644 --- a/libfreerdp/utils/ringbuffer.c +++ b/libfreerdp/utils/ringbuffer.c @@ -69,6 +69,7 @@ static BOOL ringbuffer_realloc(RingBuffer *rb, size_t targetSize) if (!newData) return FALSE; rb->readPtr = rb->writePtr = 0; + rb->buffer = newData; } else if ((rb->writePtr >= rb->readPtr) && (rb->writePtr < targetSize)) { @@ -118,6 +119,7 @@ static BOOL ringbuffer_realloc(RingBuffer *rb, size_t targetSize) } rb->writePtr = rb->size - rb->freeSize; rb->readPtr = 0; + free(rb->buffer); rb->buffer = newData; } diff --git a/libfreerdp/utils/test/TestRingBuffer.c b/libfreerdp/utils/test/TestRingBuffer.c index 36cbaa559..22e312e43 100644 --- a/libfreerdp/utils/test/TestRingBuffer.c +++ b/libfreerdp/utils/test/TestRingBuffer.c @@ -75,6 +75,7 @@ BOOL test_overlaps(void) if (ringbuffer_capacity(&rb) != 5) goto error; + ringbuffer_destroy(&rb); return TRUE; error: ringbuffer_destroy(&rb); @@ -220,6 +221,9 @@ int TestRingBuffer(int argc, char* argv[]) return -1; } fprintf(stderr, "ok\n"); + + ringbuffer_destroy(&ringBuffer); + free(tmpBuf); return 0; }