Skip to content
Snippets Groups Projects
Commit de2c5af1 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Coverity actually found legitimate issues in link_list.c

They're all from accessing list values outside of a lock.
Lock the list earlier to include these.

Also, does this mean it knows they're recursive now?
Let's find out!
parent 793cf6d9
Branches
Tags
No related merge requests found
Pipeline #7750 passed
...@@ -142,13 +142,14 @@ long listDettach(link_list_t* list) ...@@ -142,13 +142,14 @@ long listDettach(link_list_t* list)
{ {
int refs; int refs;
if(list==NULL || list->refs<1) listLock(list);
if(list==NULL || list->refs<1) {
listUnlock(list);
return(-1); return(-1);
}
listLock(list);
if((refs=--list->refs)==0) { if((refs=--list->refs)==0) {
listUnlock(list); listUnlock(list);
// coverity[sleep:SUPPRESS]
listFree(list); listFree(list);
} }
else else
...@@ -501,10 +502,12 @@ bool listNodeIsLocked(const list_node_t* node) ...@@ -501,10 +502,12 @@ bool listNodeIsLocked(const list_node_t* node)
bool listLockNode(list_node_t* node) bool listLockNode(list_node_t* node)
{ {
if(node==NULL || (node->flags&LINK_LIST_LOCKED)) listLock(node->list);
if(node==NULL || (node->flags&LINK_LIST_LOCKED)) {
listUnlock(node->list);
return(false); return(false);
}
listLock(node->list);
node->flags|=LINK_LIST_LOCKED; node->flags|=LINK_LIST_LOCKED;
listUnlock(node->list); listUnlock(node->list);
...@@ -766,7 +769,6 @@ void* listRemoveTaggedNode(link_list_t* list, list_node_tag_t tag, bool free_dat ...@@ -766,7 +769,6 @@ void* listRemoveTaggedNode(link_list_t* list, list_node_tag_t tag, bool free_dat
listLock(list); listLock(list);
// coverity[double_lock:SUPPRESS]
if((node=listFindTaggedNode(list, tag)) != NULL) if((node=listFindTaggedNode(list, tag)) != NULL)
data = list_remove_node(list, node, free_data); data = list_remove_node(list, node, free_data);
...@@ -792,12 +794,10 @@ long listRemoveNodes(link_list_t* list, list_node_t* node, long max, bool free_d ...@@ -792,12 +794,10 @@ long listRemoveNodes(link_list_t* list, list_node_t* node, long max, bool free_d
for(count=0; node!=NULL && count<max; node=next_node, count++) { for(count=0; node!=NULL && count<max; node=next_node, count++) {
next_node = node->next; next_node = node->next;
// coverity[double_lock:SUPPRESS]
if(listRemoveNode(list, node, free_data)==NULL) if(listRemoveNode(list, node, free_data)==NULL)
break; break;
} }
// coverity[double_unlock:SUPPRESS]
listUnlock(list); listUnlock(list);
return(count); return(count);
...@@ -863,12 +863,14 @@ void listReverse(link_list_t* list) ...@@ -863,12 +863,14 @@ void listReverse(link_list_t* list)
if(list == NULL) if(list == NULL)
return; return;
listLock(list);
node = list->first; node = list->first;
if(node == NULL) if(node == NULL) {
listUnlock(list);
return; return;
}
listLock(list);
list->last = list->first; list->last = list->first;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment