Bugzilla – Attachment 3303 Details for
Bug 3037
cppcheck reporting error of possible memory leak
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Proposed patch to fix the bug
0001-regress-Fix-possible-memleaks.patch (text/plain), 2.19 KB, created by
Jitendra Sharma
on 2019-07-25 16:12:33 AEST
(
hide
)
Description:
Proposed patch to fix the bug
Filename:
MIME Type:
Creator:
Jitendra Sharma
Created:
2019-07-25 16:12:33 AEST
Size:
2.19 KB
patch
obsolete
>From 1246c058ea573bcd67bf94658363929890228e05 Mon Sep 17 00:00:00 2001 >From: Jitendra Sharma <jitendra.sharma@intel.com> >Date: Wed, 24 Jul 2019 17:01:26 +0530 >Subject: [PATCH] regress: Fix possible memleaks > >malloc happens with tohex, but those allocations aren't >freed. Fix them. >--- > regress/unittests/test_helper/test_helper.c | 15 ++++++++++++--- > 1 file changed, 12 insertions(+), 3 deletions(-) > >diff --git a/regress/unittests/test_helper/test_helper.c b/regress/unittests/test_helper/test_helper.c >index e7a47b26..2270c083 100644 >--- a/regress/unittests/test_helper/test_helper.c >+++ b/regress/unittests/test_helper/test_helper.c >@@ -391,6 +391,8 @@ assert_mem(const char *file, int line, const char *a1, const char *a2, > const void *aa1, const void *aa2, size_t l, enum test_predicate pred) > { > int r; >+ char *aa1_tohex = NULL; >+ char *aa2_tohex = NULL; > > if (l == 0) > return; >@@ -401,8 +403,12 @@ assert_mem(const char *file, int line, const char *a1, const char *a2, > r = memcmp(aa1, aa2, l); > TEST_CHECK_INT(r, pred); > test_header(file, line, a1, a2, "STRING", pred); >- fprintf(stderr, "%12s = %s (len %zu)\n", a1, tohex(aa1, MIN(l, 256)), l); >- fprintf(stderr, "%12s = %s (len %zu)\n", a2, tohex(aa2, MIN(l, 256)), l); >+ aa1_tohex = tohex(aa1, MIN(l, 256)); >+ aa2_tohex = tohex(aa2, MIN(l, 256)); >+ fprintf(stderr, "%12s = %s (len %zu)\n", a1, aa1_tohex, l); >+ fprintf(stderr, "%12s = %s (len %zu)\n", a2, aa2_tohex, l); >+ free(aa1_tohex); >+ free(aa2_tohex); > test_die(); > } > >@@ -427,6 +433,7 @@ assert_mem_filled(const char *file, int line, const char *a1, > size_t where = -1; > int r; > char tmp[64]; >+ char *aa1_tohex = NULL; > > if (l == 0) > return; >@@ -436,8 +443,10 @@ assert_mem_filled(const char *file, int line, const char *a1, > r = memvalcmp(aa1, v, l, &where); > TEST_CHECK_INT(r, pred); > test_header(file, line, a1, NULL, "MEM_ZERO", pred); >+ aa1_tohex = tohex(aa1, MIN(l, 20)); > fprintf(stderr, "%20s = %s%s (len %zu)\n", a1, >- tohex(aa1, MIN(l, 20)), l > 20 ? "..." : "", l); >+ aa1_tohex, l > 20 ? "..." : "", l); >+ free(aa1_tohex); > snprintf(tmp, sizeof(tmp), "(%s)[%zu]", a1, where); > fprintf(stderr, "%20s = 0x%02x (expected 0x%02x)\n", tmp, > ((u_char *)aa1)[where], v); >-- >2.20.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 3037
: 3303