summaryrefslogtreecommitdiff
path: root/ovsdb
diff options
context:
space:
mode:
authorWilliam Tu <u9012063@gmail.com>2016-01-04 16:18:39 -0800
committerBen Pfaff <blp@ovn.org>2016-01-04 16:51:29 -0800
commitaf65491dfdb590a54736eb4756729a6f59af7350 (patch)
tree3782affa92b626828f7823c02e1100f0dc542205 /ovsdb
parentd8ce1d2c92b7f8deb4a1a069bb56359e32086cc8 (diff)
downloadopenvswitch-af65491dfdb590a54736eb4756729a6f59af7350.tar.gz
ovsdb-client: Fix memory leak reported by valgrind.
Free memory allocated from table_add_column and table_add_row. Test case: vsctl-bashcomp - basic verification/argument completion(7,8) Call stack is below: xrealloc (util.c:123) table_add_column (table.c:146) or table_add_row (table.c:172) do_list_tables (ovsdb-client.c:449) main (ovsdb-client.c:151) Signed-off-by: William Tu <u9012063@gmail.com> Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com> Co-authored-by: Daniele Di Proietto <diproiettod@vmware.com> [blp@ovn.org removed an unneeded "if"] Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'ovsdb')
-rw-r--r--ovsdb/ovsdb-client.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/ovsdb/ovsdb-client.c b/ovsdb/ovsdb-client.c
index 83cc81d92..8c4833876 100644
--- a/ovsdb/ovsdb-client.c
+++ b/ovsdb/ovsdb-client.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -84,7 +84,7 @@ int
main(int argc, char *argv[])
{
const struct ovsdb_client_command *command;
- const char *database;
+ char *database;
struct jsonrpc *rpc;
ovs_cmdl_proctitle_init(argc, argv);
@@ -128,12 +128,13 @@ main(int argc, char *argv[])
fetch_dbs(rpc, &dbs);
if (argc - optind > command->min_args
&& svec_contains(&dbs, argv[optind])) {
- database = argv[optind++];
+ database = xstrdup(argv[optind++]);
} else if (dbs.n == 1) {
database = xstrdup(dbs.names[0]);
} else if (svec_contains(&dbs, "Open_vSwitch")) {
- database = "Open_vSwitch";
+ database = xstrdup("Open_vSwitch");
} else {
+ jsonrpc_close(rpc);
ovs_fatal(0, "no default database for `%s' command, please "
"specify a database name", command->name);
}
@@ -150,6 +151,7 @@ main(int argc, char *argv[])
command->handler(rpc, database, argc - optind, argv + optind);
+ free(database);
jsonrpc_close(rpc);
if (ferror(stdout)) {
@@ -455,6 +457,7 @@ do_list_tables(struct jsonrpc *rpc, const char *database,
}
ovsdb_schema_destroy(schema);
table_print(&t, &table_style);
+ table_destroy(&t);
}
static void
@@ -493,6 +496,7 @@ do_list_columns(struct jsonrpc *rpc, const char *database,
}
ovsdb_schema_destroy(schema);
table_print(&t, &table_style);
+ table_destroy(&t);
}
static void