Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix potential (unlikely) mem leak in app/utils/dirs.c #276

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions app/utils/dirs.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ static int zsv_foreach_dirent_remove(struct zsv_foreach_dirent_handle *h, size_t
}
}
} else { // dir
struct dir_path *dn = calloc(1, sizeof(*dn));
if (!dn) {
fprintf(stderr, "Out of memory!\n");
return 1;
}
if (h->parent_and_entry) {
struct dir_path *dn = calloc(1, sizeof(*dn));
if (!dn) {
fprintf(stderr, "Out of memory!\n");
return 1;
}
dn->path = strdup(h->parent_and_entry);
dn->next = *((struct dir_path **)h->ctx);
*((struct dir_path **)h->ctx) = dn;
Expand Down Expand Up @@ -305,10 +305,14 @@ int zsv_remove_dir_recursive(const unsigned char *path) {
// delete directories in the reverse order we received them
struct dir_path *reverse_dirs = NULL;
int err = zsv_foreach_dirent((const char *)path, 0, zsv_foreach_dirent_remove, &reverse_dirs, 0);
// unlink and free each dir

// unlink each dir
for (struct dir_path *dn = reverse_dirs; !err && dn; dn = dn->next)
rmdir_w_msg(dn->path, &err);

// free each dir
for (struct dir_path *next, *dn = reverse_dirs; !err && dn; dn = next) {
next = dn->next;
rmdir_w_msg(dn->path, &err);
free(dn->path);
free(dn);
}
Expand Down