diff mbox

[4/5] checkpolicy: do not leak queue elements in queue_destroy()

Message ID 20161226211832.7165-4-nicolas.iooss@m4x.org (mailing list archive)
State Not Applicable
Headers show

Commit Message

Nicolas Iooss Dec. 26, 2016, 9:18 p.m. UTC
Elements which are inserted into a queue_t object are either NULL (from
insert_separator()) or strings allocated with malloc() in insert_id().
They would be freed if there are still present in the queue when it is
destroyed. Otherwise the memory allocated for these elements would be
leaked.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
---
 checkpolicy/queue.c | 1 +
 1 file changed, 1 insertion(+)

Comments

James Carter Jan. 6, 2017, 7:27 p.m. UTC | #1
On 12/26/2016 04:18 PM, Nicolas Iooss wrote:
> Elements which are inserted into a queue_t object are either NULL (from
> insert_separator()) or strings allocated with malloc() in insert_id().
> They would be freed if there are still present in the queue when it is
> destroyed. Otherwise the memory allocated for these elements would be
> leaked.
>
> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>

Applied.

Thanks,

> ---
>  checkpolicy/queue.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/checkpolicy/queue.c b/checkpolicy/queue.c
> index 272079c0debe..acc991c63303 100644
> --- a/checkpolicy/queue.c
> +++ b/checkpolicy/queue.c
> @@ -113,6 +113,7 @@ void queue_destroy(queue_t q)
>
>  	p = q->head;
>  	while (p != NULL) {
> +		free(p->element);
>  		temp = p;
>  		p = p->next;
>  		free(temp);
>
diff mbox

Patch

diff --git a/checkpolicy/queue.c b/checkpolicy/queue.c
index 272079c0debe..acc991c63303 100644
--- a/checkpolicy/queue.c
+++ b/checkpolicy/queue.c
@@ -113,6 +113,7 @@  void queue_destroy(queue_t q)
 
 	p = q->head;
 	while (p != NULL) {
+		free(p->element);
 		temp = p;
 		p = p->next;
 		free(temp);