diff mbox series

[ovs-dev,v2] ovsdb: Fix potential leak when making diff of conditions.

Message ID 20230922131823.2361211-1-xsimonar@redhat.com
State Accepted
Commit 4fc02650ae0ffa9275077b3fa190fe6d1d1a4e9d
Headers show
Series [ovs-dev,v2] ovsdb: Fix potential leak when making diff of conditions. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation success test: success

Commit Message

Xavier Simonart Sept. 22, 2023, 1:18 p.m. UTC
OVN unit tests highlight this:

ERROR: LeakSanitizer: detected memory leaks
Direct leak of 1344 byte(s) in 1 object(s) allocated from:
    0 0x4db0b7 in calloc (ovsdb/ovsdb-server+0x4db0b7)
    1 0x5c2162 in xcalloc__ lib/util.c:124:31
    2 0x5c221c in xcalloc lib/util.c:161:12
    3 0x54afbc in ovsdb_condition_diff ovsdb/condition.c:527:21
    4 0x529da6 in ovsdb_monitor_table_condition_update ovsdb/monitor.c:824:5
    5 0x524fa4 in ovsdb_jsonrpc_parse_monitor_cond_change_request ovsdb/jsonrpc-server.c:1557:13
    6 0x5235c3 in ovsdb_jsonrpc_monitor_cond_change ovsdb/jsonrpc-server.c:1624:25
    7 0x5217f2 in ovsdb_jsonrpc_session_got_request ovsdb/jsonrpc-server.c:1034:17
    8 0x520ee6 in ovsdb_jsonrpc_session_run ovsdb/jsonrpc-server.c:572:17
    9 0x51ffbe in ovsdb_jsonrpc_session_run_all ovsdb/jsonrpc-server.c:602:21
    10 0x51fbcf in ovsdb_jsonrpc_server_run ovsdb/jsonrpc-server.c:417:9
    11 0x517550 in main_loop ovsdb/ovsdb-server.c:224:9
    12 0x512e80 in main ovsdb/ovsdb-server.c:507:5
    13 0x7f9ecf675b74 in __libc_start_main (/lib64/libc.so.6+0x27b74)

Fixes: ef1da757f016 ("ovsdb: condition: Process condition changes incrementally.")
Signed-off-by: Xavier Simonart <xsimonar@redhat.com>

---
v2: addressed comments from Ilya.
---
 ovsdb/condition.c      | 11 ++++++++---
 ovsdb/monitor.c        |  1 +
 tests/ovsdb-monitor.at |  1 +
 3 files changed, 10 insertions(+), 3 deletions(-)

Comments

Ilya Maximets Sept. 25, 2023, 12:19 p.m. UTC | #1
On 9/22/23 15:18, Xavier Simonart wrote:
> OVN unit tests highlight this:
> 
> ERROR: LeakSanitizer: detected memory leaks
> Direct leak of 1344 byte(s) in 1 object(s) allocated from:
>     0 0x4db0b7 in calloc (ovsdb/ovsdb-server+0x4db0b7)
>     1 0x5c2162 in xcalloc__ lib/util.c:124:31
>     2 0x5c221c in xcalloc lib/util.c:161:12
>     3 0x54afbc in ovsdb_condition_diff ovsdb/condition.c:527:21
>     4 0x529da6 in ovsdb_monitor_table_condition_update ovsdb/monitor.c:824:5
>     5 0x524fa4 in ovsdb_jsonrpc_parse_monitor_cond_change_request ovsdb/jsonrpc-server.c:1557:13
>     6 0x5235c3 in ovsdb_jsonrpc_monitor_cond_change ovsdb/jsonrpc-server.c:1624:25
>     7 0x5217f2 in ovsdb_jsonrpc_session_got_request ovsdb/jsonrpc-server.c:1034:17
>     8 0x520ee6 in ovsdb_jsonrpc_session_run ovsdb/jsonrpc-server.c:572:17
>     9 0x51ffbe in ovsdb_jsonrpc_session_run_all ovsdb/jsonrpc-server.c:602:21
>     10 0x51fbcf in ovsdb_jsonrpc_server_run ovsdb/jsonrpc-server.c:417:9
>     11 0x517550 in main_loop ovsdb/ovsdb-server.c:224:9
>     12 0x512e80 in main ovsdb/ovsdb-server.c:507:5
>     13 0x7f9ecf675b74 in __libc_start_main (/lib64/libc.so.6+0x27b74)
> 
> Fixes: ef1da757f016 ("ovsdb: condition: Process condition changes incrementally.")
> Signed-off-by: Xavier Simonart <xsimonar@redhat.com>
> 
> ---
> v2: addressed comments from Ilya.
> ---
>  ovsdb/condition.c      | 11 ++++++++---
>  ovsdb/monitor.c        |  1 +
>  tests/ovsdb-monitor.at |  1 +
>  3 files changed, 10 insertions(+), 3 deletions(-)

Thanks!  Applied and backported to 3.2.

Best regards, Ilya Maximets.
diff mbox series

Patch

diff --git a/ovsdb/condition.c b/ovsdb/condition.c
index 5a3eb4e8a..4911fbf59 100644
--- a/ovsdb/condition.c
+++ b/ovsdb/condition.c
@@ -550,9 +550,14 @@  ovsdb_condition_diff(struct ovsdb_condition *diff,
                            &b->clauses[j]);
     }
 
-    diff->optimized = a->optimized && b->optimized;
-    if (diff->optimized) {
-        ovsdb_condition_optimize(diff);
+    if (diff->n_clauses) {
+        diff->optimized = a->optimized && b->optimized;
+        if (diff->optimized) {
+            ovsdb_condition_optimize(diff);
+        }
+    } else {
+        free(diff->clauses);
+        diff->clauses = NULL;
     }
 }
 
diff --git a/ovsdb/monitor.c b/ovsdb/monitor.c
index 9829cd39c..9855f45d3 100644
--- a/ovsdb/monitor.c
+++ b/ovsdb/monitor.c
@@ -821,6 +821,7 @@  ovsdb_monitor_table_condition_update(
     ovsdb_condition_destroy(&mtc->new_condition);
     ovsdb_condition_clone(&mtc->new_condition, &cond);
     ovsdb_condition_destroy(&cond);
+    ovsdb_condition_destroy(&mtc->diff_condition);
     ovsdb_condition_diff(&mtc->diff_condition,
                          &mtc->old_condition, &mtc->new_condition);
     ovsdb_monitor_condition_add_columns(dbmon,
diff --git a/tests/ovsdb-monitor.at b/tests/ovsdb-monitor.at
index 12cd2bc31..3e1df18a1 100644
--- a/tests/ovsdb-monitor.at
+++ b/tests/ovsdb-monitor.at
@@ -586,6 +586,7 @@  row,action,name,number,_version
   [[]],
   [],
   [[[[["name","==","one"],["name","==","two"]]]],
+   [[[["name","==","two"],["name","==","one"]]]],
    [[[["name","==","one"]]]],
     [[[false]]],
     [[[true]]]])