Skip to content

Commit f8c85b8

Browse files
mikhailnovstevegrubb
authored andcommitted
Fix MEMORY_LEAK.EX in delete_all.c
Add list_clear(&l) before returning -1 on error paths to prevent memory leak of rule list allocated by list_append(). Svace report: Dynamic memory, referenced by 'newnode->r', is allocated at delete_all.c:87 by calling function 'list_append' and lost at delete_all.c:79. (CWE401, CWE404, CWE775) Co-authored-by: Z.AI GLM-5
1 parent ec9ab85 commit f8c85b8

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/delete_all.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ int delete_all_rules(int fd)
7373
break;
7474

7575
if (rep.type == NLMSG_ERROR && rep.error->error) {
76-
audit_msg(LOG_ERR,
77-
"Error receiving rules list (%s)",
76+
audit_msg(LOG_ERR,
77+
"Error receiving rules list (%s)",
7878
strerror(-rep.error->error));
79+
list_clear(&l);
7980
return -1;
8081
}
8182

@@ -97,7 +98,8 @@ int delete_all_rules(int fd)
9798
rc = audit_send(fd, AUDIT_DEL_RULE, n->r, n->size);
9899
if (rc < 0) {
99100
audit_msg(LOG_ERR, "Error deleting rule (%s)",
100-
strerror(-rc));
101+
strerror(-rc));
102+
list_clear(&l);
101103
return -1;
102104
}
103105
n = list_next(&l);

0 commit comments

Comments
 (0)