Skip to content

Commit

Permalink
ksmbd-tools: fix memory leak in rpc_samr.c
Browse files Browse the repository at this point in the history
g_array_free() in rpc_samr_destroy() frees the GArray, but not the
individual entries that were appended.
This diff adds a domain_entry_free() function that will be called for
each entry when g_array_free() is called.

Found after compiling mountd with --fsanitize=address.

Signed-off-by: Marios Makassikis <[email protected]>
Signed-off-by: Namjae Jeon <[email protected]>
  • Loading branch information
Marios Makassikis authored and namjaejeon committed Jan 4, 2021
1 parent 7368ec0 commit 80ab541
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions mountd/rpc_samr.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,13 @@ static void rpc_samr_remove_domain_entry(unsigned int eidx)
free(entry);
}

static void domain_entry_free(void *v)
{
char **entry = v;

free(*entry);
}

int rpc_samr_init(void)
{
char hostname[NAME_MAX];
Expand All @@ -767,6 +774,9 @@ int rpc_samr_init(void)
domain_entries = g_array_new(0, 0, sizeof(void *));
if (!domain_entries)
return -ENOMEM;

g_array_set_clear_func(domain_entries, domain_entry_free);

/*
* ksmbd supports the standalone server and
* uses the hostname as the domain name.
Expand Down

0 comments on commit 80ab541

Please sign in to comment.