[ovs-dev] [PATCHv3 3/3] ovsdb-server.c: Fix memory leak
Ben Pfaff
blp at ovn.org
Thu Nov 2 21:17:12 UTC 2017
On Tue, Oct 31, 2017 at 10:52:10AM -0700, Yifeng Sun wrote:
> Valgrind testcase 2349 (ovn -- DSCP marking check) reports the leak below:
> 21 bytes in 21 blocks are definitely lost in loss record 24 of 362
> at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> by 0x436FD4: xmalloc (util.c:120)
> by 0x437044: xmemdup0 (util.c:150)
> by 0x408C97: add_manager_options (ovsdb-server.c:709)
> by 0x408C97: query_db_remotes (ovsdb-server.c:765)
> by 0x408C97: reconfigure_remotes (ovsdb-server.c:926)
> by 0x406273: main_loop (ovsdb-server.c:194)
> by 0x406273: main (ovsdb-server.c:434)
>
> When options are freed, options->role need to be freed explicitly.
>
> v1->v3: Amend valgrind report.
>
> Signed-off-by: Yifeng Sun <pkusunyifeng at gmail.com>
> ---
> ovsdb/ovsdb-server.c | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
> index 030d86ba467f..cd30dd48425b 100644
> --- a/ovsdb/ovsdb-server.c
> +++ b/ovsdb/ovsdb-server.c
> @@ -674,6 +674,21 @@ add_remote(struct shash *remotes, const char *target)
> return options;
> }
>
> +static void
> +free_remotes(struct shash *remotes)
> +{
> + struct ovsdb_jsonrpc_options *options;
> + struct shash_node *node;
> +
> + if (remotes) {
> + SHASH_FOR_EACH(node, remotes) {
> + options = node->data;
> + free(options->role);
> + }
> + shash_destroy_free_data(remotes);
> + }
> +}
Thanks a lot. I'll apply this to master in a minute.
Please put a space after SHASH_FOR_EACH, etc., like we do after the
"for" keyword. I fixed that up.
More information about the dev
mailing list