Skip to content

Commit

Permalink
Enhance memory management in dup node deletion
Browse files Browse the repository at this point in the history
In q_delete_dup, replace the conditional check and freeing of 'prob'
with a more clear approach. The updated code uses `free(prob)` directly,
followed by updating 'prob' with the strdup result from 'cur->val'
  • Loading branch information
YiChiChao committed Mar 4, 2024
1 parent 1227780 commit 781f46c
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,7 @@ bool q_delete_dup(struct list_head *head)
continue;
} else {
// Update the prob if cur and next have the same string
if (prob) {
free(prob);
prob = NULL;
}
free(prob);
prob = strdup(cur->value);
}
}
Expand Down

0 comments on commit 781f46c

Please sign in to comment.