qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Cc: "Hao Wu" <wuhaotsh@google.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Havard Skinnemoen" <hskinnemoen@google.com>,
	"Gan Qixin" <ganqixin@huawei.com>,
	"Euler Robot" <euler.robot@huawei.com>
Subject: [PULL 11/14] qtest/npcm7xx_pwm-test: Fix memleak in pwm_qom_get
Date: Wed, 20 Jan 2021 16:17:48 +0100	[thread overview]
Message-ID: <20210120151751.520597-12-thuth@redhat.com> (raw)
In-Reply-To: <20210120151751.520597-1-thuth@redhat.com>

From: Gan Qixin <ganqixin@huawei.com>

The pwm_qom_get function didn't free "response", which caused an indirect
memory leak. So use qobject_unref() to fix it.

ASAN shows memory leak stack:

Indirect leak of 74160000 byte(s) in 18000 object(s) allocated from:
    #0 0x7f96e2f79d4e in __interceptor_calloc (/lib64/libasan.so.5+0x112d4e)
    #1 0x7f96e2d98a50 in g_malloc0 (/lib64/libglib-2.0.so.0+0x55a50)
    #2 0x556313112180 in qdict_new ../qobject/qdict.c:30
    #3 0x556313115bca in parse_object ../qobject/json-parser.c:318
    #4 0x556313117810 in parse_value ../qobject/json-parser.c:546
    #5 0x556313117bda in json_parser_parse ../qobject/json-parser.c:580
    #6 0x55631310fe67 in json_message_process_token ../qobject/json-streamer.c:92
    #7 0x5563131210b7 in json_lexer_feed_char ../qobject/json-lexer.c:313
    #8 0x556313121662 in json_lexer_feed ../qobject/json-lexer.c:350
    #9 0x5563131101e9 in json_message_parser_feed ../qobject/json-streamer.c:121
    #10 0x5563130cb81e in qmp_fd_receive ../tests/qtest/libqtest.c:614
    #11 0x5563130cba2b in qtest_qmp_receive_dict ../tests/qtest/libqtest.c:636
    #12 0x5563130cb939 in qtest_qmp_receive ../tests/qtest/libqtest.c:624
    #13 0x5563130cbe0d in qtest_vqmp ../tests/qtest/libqtest.c:715
    #14 0x5563130cc40f in qtest_qmp ../tests/qtest/libqtest.c:756
    #15 0x5563130c5623 in pwm_qom_get ../tests/qtest/npcm7xx_pwm-test.c:180
    #16 0x5563130c595e in pwm_get_duty ../tests/qtest/npcm7xx_pwm-test.c:210
    #17 0x5563130c7529 in test_toggle ../tests/qtest/npcm7xx_pwm-test.c:447

Reported-by: Euler Robot <euler.robot@huawei.com>
Message-Id: <20210115075634.717909-1-ganqixin@huawei.com>
Signed-off-by: Gan Qixin <ganqixin@huawei.com>
Reviewed-by: Havard Skinnemoen <hskinnemoen@google.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Hao Wu <wuhaotsh@google.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 tests/qtest/npcm7xx_pwm-test.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tests/qtest/npcm7xx_pwm-test.c b/tests/qtest/npcm7xx_pwm-test.c
index 33fbdf5f54..63557d2c06 100644
--- a/tests/qtest/npcm7xx_pwm-test.c
+++ b/tests/qtest/npcm7xx_pwm-test.c
@@ -175,6 +175,7 @@ static int pwm_index(const PWM *pwm)
 static uint64_t pwm_qom_get(QTestState *qts, const char *path, const char *name)
 {
     QDict *response;
+    uint64_t val;
 
     g_test_message("Getting properties %s from %s", name, path);
     response = qtest_qmp(qts, "{ 'execute': 'qom-get',"
@@ -182,7 +183,9 @@ static uint64_t pwm_qom_get(QTestState *qts, const char *path, const char *name)
             path, name);
     /* The qom set message returns successfully. */
     g_assert_true(qdict_haskey(response, "return"));
-    return qnum_get_uint(qobject_to(QNum, qdict_get(response, "return")));
+    val = qnum_get_uint(qobject_to(QNum, qdict_get(response, "return")));
+    qobject_unref(response);
+    return val;
 }
 
 static uint64_t pwm_get_freq(QTestState *qts, int module_index, int pwm_index)
-- 
2.27.0



  parent reply	other threads:[~2021-01-20 15:28 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-20 15:17 [PULL 00/14] gitlab-CI, qtests and misc patches Thomas Huth
2021-01-20 15:17 ` [PULL 01/14] osdep.h: Remove <sys/signal.h> include Thomas Huth
2021-01-20 15:17 ` [PULL 02/14] configure: Add sys/timex.h to probe clock_adjtime Thomas Huth
2021-01-20 15:17 ` [PULL 03/14] libvhost-user: Include poll.h instead of sys/poll.h Thomas Huth
2021-01-20 15:17 ` [PULL 04/14] hw/block/nand: Rename PAGE_SIZE to NAND_PAGE_SIZE Thomas Huth
2021-01-20 15:17 ` [PULL 05/14] elf2dmp: Rename PAGE_SIZE to ELF2DMP_PAGE_SIZE Thomas Huth
2021-01-20 15:17 ` [PULL 06/14] tests: Rename PAGE_SIZE definitions Thomas Huth
2021-01-20 15:17 ` [PULL 07/14] accel/kvm: avoid using predefined PAGE_SIZE Thomas Huth
2021-01-20 15:17 ` [PULL 08/14] tests/docker: Add dockerfile for Alpine Linux Thomas Huth
2021-01-20 15:17 ` [PULL 09/14] tests/check-block.sh: Refuse to run the iotests with BusyBox' sed Thomas Huth
2021-01-20 15:17 ` [PULL 10/14] gitlab-ci: Add alpine to pipeline Thomas Huth
2021-01-20 15:17 ` Thomas Huth [this message]
2021-01-20 15:17 ` [PULL 12/14] tests: Fix memory leak in tpm-util.c Thomas Huth
2021-01-20 15:17 ` [PULL 13/14] MAINTAINERS: Remove Ben Warren Thomas Huth
2021-01-20 15:17 ` [PULL 14/14] MAINTAINERS: Make status spellings consistent Thomas Huth
2021-01-21  9:40 ` [PULL 00/14] gitlab-CI, qtests and misc patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210120151751.520597-12-thuth@redhat.com \
    --to=thuth@redhat.com \
    --cc=euler.robot@huawei.com \
    --cc=f4bug@amsat.org \
    --cc=ganqixin@huawei.com \
    --cc=hskinnemoen@google.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=wuhaotsh@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).