Skip to content

Commit

Permalink
ovsdb-server: Fix memory leak
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Yifeng Sun <pkusunyifeng@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
  • Loading branch information
yifsun authored and blp committed Nov 2, 2017
1 parent 93236ad commit e1ca91b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ovsdb/ovsdb-server.c
Expand Up @@ -674,6 +674,20 @@ add_remote(struct shash *remotes, const char *target)
return options;
}

static void
free_remotes(struct shash *remotes)
{
if (remotes) {
struct shash_node *node;

SHASH_FOR_EACH (node, remotes) {
struct ovsdb_jsonrpc_options *options = node->data;
free(options->role);
}
shash_destroy_free_data(remotes);
}
}

/* Adds a remote and options to 'remotes', based on the Manager table row in
* 'row'. */
static void
Expand Down Expand Up @@ -929,7 +943,7 @@ reconfigure_remotes(struct ovsdb_jsonrpc_server *jsonrpc,
}
}
ovsdb_jsonrpc_server_set_remotes(jsonrpc, &resolved_remotes);
shash_destroy_free_data(&resolved_remotes);
free_remotes(&resolved_remotes);

return errors.string;
}
Expand Down

0 comments on commit e1ca91b

Please sign in to comment.