bugfix: lib: fix memory leaks in syscall_in_list() (#7098)

`asprintf()` overwrites the value of `ptr->xxx` with the new pointer.
Result: the older allocation is never freed.
This commit is contained in:
pierretom 2026-03-12 07:39:38 +01:00 committed by GitHub
parent e01e2c1740
commit 05e0d44288
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2669,8 +2669,10 @@ static void syscall_in_list(int fd, int syscall, int arg, void *ptrarg, bool nat
// if found in the problem list, add to post-exec list
if (sl.found) {
if (ptr->postlist) {
if (asprintf(&ptr->postlist, "%s,%s", ptr->postlist, name) == -1)
char *old = ptr->postlist;
if (asprintf(&ptr->postlist, "%s,%s", old, name) == -1)
errExit("asprintf");
free(old);
}
else
ptr->postlist = strdup(name);
@ -2689,8 +2691,10 @@ static void syscall_in_list(int fd, int syscall, int arg, void *ptrarg, bool nat
}
if (ptr->prelist) {
if (asprintf(&ptr->prelist, "%s,%s", ptr->prelist, newcall) == -1)
char *old = ptr->prelist;
if (asprintf(&ptr->prelist, "%s,%s", old, newcall) == -1)
errExit("asprintf");
free(old);
free(newcall);
}
else