Harald Welte has submitted this change and it was merged.

Change subject: ctrl: fix mem leak when handling GET_REPLY and SET_REPLY
......................................................................


ctrl: fix mem leak when handling GET_REPLY and SET_REPLY

In ctrl_handle_msg() (code recently propagated from handle_control_read()),
talloc_free() the parsed ctrl_cmd in all code paths. In particular, a free was
missing in case ctrl_cmd_handle() returns CTRL_CMD_HANDLED.

CTRL_CMD_HANDLED is triggered by GET_REPLY / SET_REPLY parsing, as show by
ctrl_test.c. With the memleak fixed, adjust expected test output and make a
detected mem leak abort the test immediately.

Change-Id: Id583b413f8b8bd16e5cf92a8a9e8663903646381
---
M src/ctrl/control_if.c
M tests/ctrl/ctrl_test.c
M tests/ctrl/ctrl_test.ok
3 files changed, 3 insertions(+), 7 deletions(-)

Approvals:
  Max: Looks good to me, but someone else must approve
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/ctrl/control_if.c b/src/ctrl/control_if.c
index 7c1d81a..5c73b63 100644
--- a/src/ctrl/control_if.c
+++ b/src/ctrl/control_if.c
@@ -387,7 +387,6 @@
                cmd->ccon = ccon;
                if (ctrl_cmd_handle(ctrl, cmd, ctrl->data) != CTRL_CMD_HANDLED) 
{
                        ctrl_cmd_send(&ccon->write_queue, cmd);
-                       talloc_free(cmd);
                }
        } else {
                cmd = talloc_zero(ccon, struct ctrl_cmd);
@@ -398,9 +397,9 @@
                cmd->id = "err";
                cmd->reply = "Command parser error.";
                ctrl_cmd_send(&ccon->write_queue, cmd);
-               talloc_free(cmd);
        }
 
+       talloc_free(cmd);
        return 0;
 }
 
diff --git a/tests/ctrl/ctrl_test.c b/tests/ctrl/ctrl_test.c
index 9c7316f..e25929c 100644
--- a/tests/ctrl/ctrl_test.c
+++ b/tests/ctrl/ctrl_test.c
@@ -120,9 +120,8 @@
 
        if (talloc_total_size(ctx) != ctx_size_was) {
                printf("mem leak!\n");
-               // hide mem leak to be fixed in subsequent patch
-               //talloc_report_full(ctx, stdout);
-               //OSMO_ASSERT(false);
+               talloc_report_full(ctx, stdout);
+               OSMO_ASSERT(false);
        }
 
        printf("ok\n");
diff --git a/tests/ctrl/ctrl_test.ok b/tests/ctrl/ctrl_test.ok
index 9ddcfdb..210c599 100644
--- a/tests/ctrl/ctrl_test.ok
+++ b/tests/ctrl/ctrl_test.ok
@@ -167,7 +167,6 @@
 value = '(null)'
 reply = 'OK'
 handling:
-mem leak!
 ok
 test: 'SET_REPLY 1 variable OK'
 parsing:
@@ -176,5 +175,4 @@
 value = '(null)'
 reply = 'OK'
 handling:
-mem leak!
 ok

-- 
To view, visit https://gerrit.osmocom.org/5434
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id583b413f8b8bd16e5cf92a8a9e8663903646381
Gerrit-PatchSet: 5
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofm...@sysmocom.de>
Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msur...@sysmocom.de>

Reply via email to