Skip to content

Commit 232542c

Browse files
committed
Fix double free error
Removed the free(old) call from the _twin_queue_delete function, consolidating memory deallocation into the _twin_queue_review_order function. This change improves memory management and enhances the maintainability of the code. The fix was verified on the fbdev backend using GDB to confirm that old is properly freed during the execution of free(q) in the _twin_queue_review_order function. Additionally, on the same backend, AddressSanitizer was used to confirm the absence of memory leaks and double free issues. Close #75
1 parent 2cc4b56 commit 232542c

File tree

2 files changed

+0
-6
lines changed

2 files changed

+0
-6
lines changed

include/twin_private.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,6 @@ void _twin_path_sfinish(twin_path_t *path);
453453
typedef struct _twin_queue {
454454
struct _twin_queue *next;
455455
struct _twin_queue *order;
456-
bool walking;
457456
bool deleted;
458457
} twin_queue_t;
459458

src/queue.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ void _twin_queue_insert(twin_queue_t **head,
1919
break;
2020
new->next = *prev;
2121
new->order = 0;
22-
new->walking = false;
2322
new->deleted = false;
2423
*prev = new;
2524
}
@@ -54,8 +53,6 @@ void _twin_queue_delete(twin_queue_t **head, twin_queue_t *old)
5453
{
5554
_twin_queue_remove(head, old);
5655
old->deleted = true;
57-
if (!old->walking)
58-
free(old);
5956
}
6057

6158
twin_queue_t *_twin_queue_set_order(twin_queue_t **head)
@@ -64,7 +61,6 @@ twin_queue_t *_twin_queue_set_order(twin_queue_t **head)
6461

6562
for (twin_queue_t *q = first; q; q = q->next) {
6663
q->order = q->next;
67-
q->walking = true;
6864
}
6965
return first;
7066
}
@@ -76,7 +72,6 @@ void _twin_queue_review_order(twin_queue_t *first)
7672
for (q = first; q; q = o) {
7773
o = q->order;
7874
q->order = 0;
79-
q->walking = false;
8075
if (q->deleted)
8176
free(q);
8277
}

0 commit comments

Comments
 (0)