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 <agl@google.com>
This commit is contained in:
parent
491b9219a9
commit
3bb4178206
@ -56,6 +56,7 @@
|
||||
|
||||
#include <openssl/pqueue.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <openssl/mem.h>
|
||||
@ -104,6 +105,8 @@ void pqueue_free(pqueue_s *pq) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* The queue must be empty. */
|
||||
assert(pq->items == NULL);
|
||||
OPENSSL_free(pq);
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,17 @@
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user