mirror of
https://github.com/libssh2/libssh2.git
synced 2025-07-29 13:01:14 +03:00
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:
@ -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);
|
||||
|
Reference in New Issue
Block a user