[ovs-dev,3/4] ovsdb-client: Fix memory leaks

Message ID 1515779132-28902-3-git-send-email-pkusunyifeng@gmail.com
State Accepted
Headers show
Series
  • [ovs-dev,1/4] pinctrl: Fix memory leak
Related show

Commit Message

Yifeng Sun Jan. 12, 2018, 5:45 p.m.
This two leaks are reported by valgrind (testing ovsdb-client
backup and restore):

890 (56 direct, 834 indirect) bytes in 1 blocks are definitely lost in loss record 71 of 73
   by 0x42DE22: xcalloc (util.c:103)                                   
   by 0x40DD8C: ovsdb_schema_create (ovsdb.c:34)                       
   by 0x40E0B5: ovsdb_schema_from_json (ovsdb.c:196)                   
   by 0x406DA5: fetch_schema (ovsdb-client.c:415)                      
   by 0x408478: do_restore (ovsdb-client.c:1595)                       
   by 0x405BCD: main (ovsdb-client.c:170)                              

2,688 (88 direct, 2,600 indirect) bytes in 1 blocks are definitely lost in loss record 73 of 73
   by 0x42DE84: xmalloc (util.c:120)                                   
   by 0x40E61F: ovsdb_create (ovsdb.c:329)                             
   by 0x40BA22: ovsdb_file_open__ (file.c:201)                         
   by 0x40845A: do_restore (ovsdb-client.c:1592)                       
   by 0x405BCD: main (ovsdb-client.c:170)   

Signed-off-by: Yifeng Sun <pkusunyifeng@gmail.com>
---
 ovsdb/ovsdb-client.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Ben Pfaff Jan. 23, 2018, 12:42 a.m. | #1
On Fri, Jan 12, 2018 at 09:45:31AM -0800, Yifeng Sun wrote:
> This two leaks are reported by valgrind (testing ovsdb-client
> backup and restore):
> 
> 890 (56 direct, 834 indirect) bytes in 1 blocks are definitely lost in loss record 71 of 73
>    by 0x42DE22: xcalloc (util.c:103)                                   
>    by 0x40DD8C: ovsdb_schema_create (ovsdb.c:34)                       
>    by 0x40E0B5: ovsdb_schema_from_json (ovsdb.c:196)                   
>    by 0x406DA5: fetch_schema (ovsdb-client.c:415)                      
>    by 0x408478: do_restore (ovsdb-client.c:1595)                       
>    by 0x405BCD: main (ovsdb-client.c:170)                              
> 
> 2,688 (88 direct, 2,600 indirect) bytes in 1 blocks are definitely lost in loss record 73 of 73
>    by 0x42DE84: xmalloc (util.c:120)                                   
>    by 0x40E61F: ovsdb_create (ovsdb.c:329)                             
>    by 0x40BA22: ovsdb_file_open__ (file.c:201)                         
>    by 0x40845A: do_restore (ovsdb-client.c:1592)                       
>    by 0x405BCD: main (ovsdb-client.c:170)   
> 
> Signed-off-by: Yifeng Sun <pkusunyifeng@gmail.com>

Thanks, applied to master and branch-2.9.

Patch

diff --git a/ovsdb/ovsdb-client.c b/ovsdb/ovsdb-client.c
index 0ab4d66..faa6bdb 100644
--- a/ovsdb/ovsdb-client.c
+++ b/ovsdb/ovsdb-client.c
@@ -1612,6 +1612,7 @@  do_restore(struct jsonrpc *rpc, const char *database,
         VLOG_INFO("%s", ds_cstr(&s));
         ds_destroy(&s);
     }
+    ovsdb_schema_destroy(schema2);
 
     struct json *txn = json_array_create_empty();
     json_array_add(txn, json_string_create(schema->name));
@@ -1653,6 +1654,7 @@  do_restore(struct jsonrpc *rpc, const char *database,
             json_array_add(txn, ins_op);
         }
     }
+    ovsdb_destroy(backup);
     struct jsonrpc_msg *rq = jsonrpc_create_request("transact", txn, NULL);
     struct jsonrpc_msg *reply;
     check_txn(jsonrpc_transact_block(rpc, rq, &reply), &reply);