From 3bb4178206f63c92f0b417157d0874143da01f44 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Wed, 11 Feb 2015 14:16:28 -0500 Subject: [PATCH] Fix memory leak in pqueue_test. pqueue_free requires the queue be empty. Change-Id: I633e18fe71ddec51d6005210fcb6570ef53b9808 Reviewed-on: https://boringssl-review.googlesource.com/3410 Reviewed-by: Adam Langley --- ssl/pqueue/pqueue.c | 3 +++ ssl/pqueue/pqueue_test.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ssl/pqueue/pqueue.c b/ssl/pqueue/pqueue.c index ecaa1399..14bd9b63 100644 --- a/ssl/pqueue/pqueue.c +++ b/ssl/pqueue/pqueue.c @@ -56,6 +56,7 @@ #include +#include #include #include @@ -104,6 +105,8 @@ void pqueue_free(pqueue_s *pq) { return; } + /* The queue must be empty. */ + assert(pq->items == NULL); OPENSSL_free(pq); } diff --git a/ssl/pqueue/pqueue_test.c b/ssl/pqueue/pqueue_test.c index c4b4b9df..cb688f72 100644 --- a/ssl/pqueue/pqueue_test.c +++ b/ssl/pqueue/pqueue_test.c @@ -19,6 +19,17 @@ #include +static void clear_and_free_queue(pqueue q) { + for (;;) { + pitem *item = pqueue_pop(q); + if (item == NULL) { + break; + } + pitem_free(item); + } + pqueue_free(q); +} + static int trivial(void) { pqueue q = pqueue_new(); if (q == NULL) { @@ -37,7 +48,7 @@ static int trivial(void) { return 0; } pitem_free(item); - pqueue_free(q); + clear_and_free_queue(q); return 1; } @@ -101,7 +112,7 @@ static int fixed_random(void) { } curr = next; } - pqueue_free(q); + clear_and_free_queue(q); return 1; }