From 372e402713a1d4337ffce5f56d5c5c9ed99a66d0 Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Mon, 12 Oct 2015 21:07:41 +0300 Subject: [PATCH] Tests: Add tests for the two bugs fixed in index.c. --- tests/test_index.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_index.c b/tests/test_index.c index 06b4d6ba..ce2cfe10 100644 --- a/tests/test_index.c +++ b/tests/test_index.c @@ -630,6 +630,22 @@ test_corrupt(void) } +// Allocator that succeeds for the first two allocation but fails the rest. +static void * +my_alloc(void *opaque, size_t a, size_t b) +{ + (void)opaque; + + static unsigned count = 0; + if (++count > 2) + return NULL; + + return malloc(a * b); +} + +static const lzma_allocator my_allocator = { &my_alloc, NULL, NULL }; + + int main(void) { @@ -655,5 +671,19 @@ main(void) test_corrupt(); + // Test for the bug fix 21515d79d778b8730a434f151b07202d52a04611: + // liblzma: Fix lzma_index_dup() for empty Streams. + i = create_empty(); + expect(lzma_index_stream_padding(i, 4) == LZMA_OK); + test_copy(i); + lzma_index_end(i, NULL); + + // Test for the bug fix 3bf857edfef51374f6f3fffae3d817f57d3264a0: + // liblzma: Fix a memory leak in error path of lzma_index_dup(). + // Use Valgrind to see that there are no leaks. + i = create_small(); + expect(lzma_index_dup(i, &my_allocator) == NULL); + lzma_index_end(i, NULL); + return 0; }