examples/x11.c: fix invalid removal of first list element

Fix use of memory after it was being freed.
Detected by clang scan in line 56, column 12.
This commit is contained in:
Marc Hoersken 2014-12-27 13:48:51 +01:00
parent 3e47ca8a32
commit 477e609a84

View File

@ -48,13 +48,13 @@ static void remove_node(struct chan_X11_list *elem)
current_node = gp_x11_chan;
if (gp_x11_chan == elem) {
/* Removing the only one element in the list */
free(gp_x11_chan);
gp_x11_chan = NULL;
gp_x11_chan = gp_x11_chan->next;
free(current_node);
return;
}
while( current_node->next != NULL) {
if (current_node->next ==elem) {
while (current_node->next != NULL) {
if (current_node->next == elem) {
current_node->next = current_node->next->next;
current_node = current_node->next;
free(current_node);