Fix some corner cases in ringbuffer and make unitary test have no leak
This commit is contained in:
parent
5234e05843
commit
a04843bc9e
@ -69,6 +69,7 @@ static BOOL ringbuffer_realloc(RingBuffer *rb, size_t targetSize)
|
|||||||
if (!newData)
|
if (!newData)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
rb->readPtr = rb->writePtr = 0;
|
rb->readPtr = rb->writePtr = 0;
|
||||||
|
rb->buffer = newData;
|
||||||
}
|
}
|
||||||
else if ((rb->writePtr >= rb->readPtr) && (rb->writePtr < targetSize))
|
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->writePtr = rb->size - rb->freeSize;
|
||||||
rb->readPtr = 0;
|
rb->readPtr = 0;
|
||||||
|
free(rb->buffer);
|
||||||
rb->buffer = newData;
|
rb->buffer = newData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +75,7 @@ BOOL test_overlaps(void)
|
|||||||
if (ringbuffer_capacity(&rb) != 5)
|
if (ringbuffer_capacity(&rb) != 5)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
ringbuffer_destroy(&rb);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
error:
|
error:
|
||||||
ringbuffer_destroy(&rb);
|
ringbuffer_destroy(&rb);
|
||||||
@ -220,6 +221,9 @@ int TestRingBuffer(int argc, char* argv[])
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
fprintf(stderr, "ok\n");
|
fprintf(stderr, "ok\n");
|
||||||
|
|
||||||
|
ringbuffer_destroy(&ringBuffer);
|
||||||
|
free(tmpBuf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user