All of lore.kernel.org
 help / color / mirror / Atom feed
* [linux-nfc] [neard][PATCH 0/7] Fixes for more memory issues
@ 2021-07-16 10:08 ` Krzysztof Kozlowski
  0 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-16 10:08 UTC (permalink / raw)
  To: linux-nfc; +Cc: Krzysztof Kozlowski

Hi,

Few memory leaks (not finished - test-snep-read has still one which
I don't know how to fix yet), one memory corruption and minor
improvements:

This is on top of my previous patchsets (from latest):
1. -Wformat=2 and few memory leaks
   https://lore.kernel.org/linux-nfc/20210714110518.104655-1-krzysztof.kozlowski@canonical.com/T/#t

2. fixes and improvements for neard (continued)
   https://lore.kernel.org/linux-nfc/20210711202102.18094-1-krzysztof.kozlowski@canonical.com/T/#t

3. neard CI under Github and rouund of fixes
   https://lore.kernel.org/linux-nfc/20210710033859.3989-1-krzysztof.kozlowski@canonical.com/T/#t

The patchset is also available on:
https://github.com/krzk/neard
branch: dev-asan-ubsan-continued

Best regards,
Krzysztof


Krzysztof Kozlowski (7):
  snep: do not open-code freeing ndef message
  unit: fix memory leaks in test-ndef-build
  snep: remove useless NULL-ify of local pointer variable
  snep: fix double free of GSList
  unit: fix memory leaks in test-snep-read error paths
  unit: fix record memory leak in test-snep-read
  unit: fix records GList memory leak in test-snep-read

 src/snep.c             | 10 ++--------
 unit/test-ndef-build.c |  6 ++++++
 unit/test-snep-read.c  | 11 ++++++++---
 unit/test-utils.c      |  8 --------
 unit/test-utils.h      |  2 --
 5 files changed, 16 insertions(+), 21 deletions(-)

-- 
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [neard][PATCH 0/7] Fixes for more memory issues
@ 2021-07-16 10:08 ` Krzysztof Kozlowski
  0 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-16 10:08 UTC (permalink / raw)
  To: linux-nfc

[-- Attachment #1: Type: text/plain, Size: 1425 bytes --]

Hi,

Few memory leaks (not finished - test-snep-read has still one which
I don't know how to fix yet), one memory corruption and minor
improvements:

This is on top of my previous patchsets (from latest):
1. -Wformat=2 and few memory leaks
   https://lore.kernel.org/linux-nfc/20210714110518.104655-1-krzysztof.kozlowski(a)canonical.com/T/#t

2. fixes and improvements for neard (continued)
   https://lore.kernel.org/linux-nfc/20210711202102.18094-1-krzysztof.kozlowski(a)canonical.com/T/#t

3. neard CI under Github and rouund of fixes
   https://lore.kernel.org/linux-nfc/20210710033859.3989-1-krzysztof.kozlowski(a)canonical.com/T/#t

The patchset is also available on:
https://github.com/krzk/neard
branch: dev-asan-ubsan-continued

Best regards,
Krzysztof


Krzysztof Kozlowski (7):
  snep: do not open-code freeing ndef message
  unit: fix memory leaks in test-ndef-build
  snep: remove useless NULL-ify of local pointer variable
  snep: fix double free of GSList
  unit: fix memory leaks in test-snep-read error paths
  unit: fix record memory leak in test-snep-read
  unit: fix records GList memory leak in test-snep-read

 src/snep.c             | 10 ++--------
 unit/test-ndef-build.c |  6 ++++++
 unit/test-snep-read.c  | 11 ++++++++---
 unit/test-utils.c      |  8 --------
 unit/test-utils.h      |  2 --
 5 files changed, 16 insertions(+), 21 deletions(-)

-- 
2.27.0

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [linux-nfc] [neard][PATCH 1/7] snep: do not open-code freeing ndef message
  2021-07-16 10:08 ` Krzysztof Kozlowski
@ 2021-07-16 10:08   ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-16 10:08 UTC (permalink / raw)
  To: linux-nfc; +Cc: Krzysztof Kozlowski

Use near_ndef_msg_free() instead of open-coding it.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 src/snep.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/src/snep.c b/src/snep.c
index c0a1d1a00491..a1e90243c020 100644
--- a/src/snep.c
+++ b/src/snep.c
@@ -147,8 +147,7 @@ void near_snep_core_parse_handover_record(int client_fd, uint8_t *ndef,
 	near_snep_core_response_with_info(client_fd, NEAR_SNEP_RESP_SUCCESS,
 								msg->data, msg->length);
 
-	g_free(msg->data);
-	g_free(msg);
+	near_ndef_msg_free(msg);
 }
 
 /*
@@ -787,9 +786,7 @@ done:
 		}
 	}
 
-	if (ndef)
-		g_free(ndef->data);
-	g_free(ndef);
+	near_ndef_msg_free(ndef);
 }
 
 /* SNEP Core: on P2P push */
-- 
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [neard][PATCH 1/7] snep: do not open-code freeing ndef message
@ 2021-07-16 10:08   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-16 10:08 UTC (permalink / raw)
  To: linux-nfc

[-- Attachment #1: Type: text/plain, Size: 780 bytes --]

Use near_ndef_msg_free() instead of open-coding it.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 src/snep.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/src/snep.c b/src/snep.c
index c0a1d1a00491..a1e90243c020 100644
--- a/src/snep.c
+++ b/src/snep.c
@@ -147,8 +147,7 @@ void near_snep_core_parse_handover_record(int client_fd, uint8_t *ndef,
 	near_snep_core_response_with_info(client_fd, NEAR_SNEP_RESP_SUCCESS,
 								msg->data, msg->length);
 
-	g_free(msg->data);
-	g_free(msg);
+	near_ndef_msg_free(msg);
 }
 
 /*
@@ -787,9 +786,7 @@ done:
 		}
 	}
 
-	if (ndef)
-		g_free(ndef->data);
-	g_free(ndef);
+	near_ndef_msg_free(ndef);
 }
 
 /* SNEP Core: on P2P push */
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [linux-nfc] [neard][PATCH 2/7] unit: fix memory leaks in test-ndef-build
  2021-07-16 10:08 ` Krzysztof Kozlowski
@ 2021-07-16 10:08   ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-16 10:08 UTC (permalink / raw)
  To: linux-nfc; +Cc: Krzysztof Kozlowski

test-ndef-build.c was not freeing the ndef records it got leading to
memory leaks.  Report by valgrind:

  (24 direct, 15 indirect) bytes in 1 blocks are definitely lost in loss record 24 of 38
    at 0x483ED99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x11C176: ndef_message_alloc_complete.constprop.0 (ndef.c:1654)
    by 0x11FEC5: ndef_message_alloc (ndef.c:1760)
    by 0x11FEC5: near_ndef_prepare_text_record (ndef.c:3142)
    by 0x121676: test_ndef_text_build (test-ndef-build.c:63)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2B9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2D4: g_test_run (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x10F5A1: main (test-ndef-build.c:113)

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 unit/test-ndef-build.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/unit/test-ndef-build.c b/unit/test-ndef-build.c
index 44dce4bf9aef..54b502f4a40b 100644
--- a/unit/test-ndef-build.c
+++ b/unit/test-ndef-build.c
@@ -65,6 +65,8 @@ static void test_ndef_text_build(void)
 	g_assert(ndef);
 	g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(text));
 	g_assert_cmpmem(ndef->data, ARRAY_SIZE(text), text, ARRAY_SIZE(text));
+
+	near_ndef_msg_free(ndef);
 }
 
 static void test_ndef_wsc_with_passphrase_build(void)
@@ -76,6 +78,8 @@ static void test_ndef_wsc_with_passphrase_build(void)
 	g_assert(ndef);
 	g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(wsc));
 	g_assert_cmpmem(ndef->data, ARRAY_SIZE(wsc), wsc, ARRAY_SIZE(wsc));
+
+	near_ndef_msg_free(ndef);
 }
 
 static void test_ndef_wsc_with_out_passphrase_build(void)
@@ -87,6 +91,8 @@ static void test_ndef_wsc_with_out_passphrase_build(void)
 	g_assert(ndef);
 	g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(wsc_wo));
 	g_assert_cmpmem(ndef->data, ARRAY_SIZE(wsc_wo), wsc_wo, ARRAY_SIZE(wsc_wo));
+
+	near_ndef_msg_free(ndef);
 }
 
 static void test_ndef_wsc_with_out_ssid_build(void)
-- 
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [neard][PATCH 2/7] unit: fix memory leaks in test-ndef-build
@ 2021-07-16 10:08   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-16 10:08 UTC (permalink / raw)
  To: linux-nfc

[-- Attachment #1: Type: text/plain, Size: 2200 bytes --]

test-ndef-build.c was not freeing the ndef records it got leading to
memory leaks.  Report by valgrind:

  (24 direct, 15 indirect) bytes in 1 blocks are definitely lost in loss record 24 of 38
    at 0x483ED99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x11C176: ndef_message_alloc_complete.constprop.0 (ndef.c:1654)
    by 0x11FEC5: ndef_message_alloc (ndef.c:1760)
    by 0x11FEC5: near_ndef_prepare_text_record (ndef.c:3142)
    by 0x121676: test_ndef_text_build (test-ndef-build.c:63)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2B9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2D4: g_test_run (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x10F5A1: main (test-ndef-build.c:113)

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 unit/test-ndef-build.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/unit/test-ndef-build.c b/unit/test-ndef-build.c
index 44dce4bf9aef..54b502f4a40b 100644
--- a/unit/test-ndef-build.c
+++ b/unit/test-ndef-build.c
@@ -65,6 +65,8 @@ static void test_ndef_text_build(void)
 	g_assert(ndef);
 	g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(text));
 	g_assert_cmpmem(ndef->data, ARRAY_SIZE(text), text, ARRAY_SIZE(text));
+
+	near_ndef_msg_free(ndef);
 }
 
 static void test_ndef_wsc_with_passphrase_build(void)
@@ -76,6 +78,8 @@ static void test_ndef_wsc_with_passphrase_build(void)
 	g_assert(ndef);
 	g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(wsc));
 	g_assert_cmpmem(ndef->data, ARRAY_SIZE(wsc), wsc, ARRAY_SIZE(wsc));
+
+	near_ndef_msg_free(ndef);
 }
 
 static void test_ndef_wsc_with_out_passphrase_build(void)
@@ -87,6 +91,8 @@ static void test_ndef_wsc_with_out_passphrase_build(void)
 	g_assert(ndef);
 	g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(wsc_wo));
 	g_assert_cmpmem(ndef->data, ARRAY_SIZE(wsc_wo), wsc_wo, ARRAY_SIZE(wsc_wo));
+
+	near_ndef_msg_free(ndef);
 }
 
 static void test_ndef_wsc_with_out_ssid_build(void)
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [linux-nfc] [neard][PATCH 3/7] snep: remove useless NULL-ify of local pointer variable
  2021-07-16 10:08 ` Krzysztof Kozlowski
@ 2021-07-16 10:08   ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-16 10:08 UTC (permalink / raw)
  To: linux-nfc; +Cc: Krzysztof Kozlowski

Assigning NULL to a local variable (a pointer) at the end of function
does not have any effect as this NULL is not passed outside.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 src/snep.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/snep.c b/src/snep.c
index a1e90243c020..737060139b07 100644
--- a/src/snep.c
+++ b/src/snep.c
@@ -206,7 +206,6 @@ static void free_snep_core_fragment(gpointer data)
 		g_free(fragment->data);
 
 	g_free(fragment);
-	fragment = NULL;
 }
 
 static void free_snep_core_push_data(gpointer userdata, int status)
-- 
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [neard][PATCH 3/7] snep: remove useless NULL-ify of local pointer variable
@ 2021-07-16 10:08   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-16 10:08 UTC (permalink / raw)
  To: linux-nfc

[-- Attachment #1: Type: text/plain, Size: 614 bytes --]

Assigning NULL to a local variable (a pointer) at the end of function
does not have any effect as this NULL is not passed outside.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 src/snep.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/snep.c b/src/snep.c
index a1e90243c020..737060139b07 100644
--- a/src/snep.c
+++ b/src/snep.c
@@ -206,7 +206,6 @@ static void free_snep_core_fragment(gpointer data)
 		g_free(fragment->data);
 
 	g_free(fragment);
-	fragment = NULL;
 }
 
 static void free_snep_core_push_data(gpointer userdata, int status)
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [linux-nfc] [neard][PATCH 4/7] snep: fix double free of GSList
  2021-07-16 10:08 ` Krzysztof Kozlowski
@ 2021-07-16 10:08   ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-16 10:08 UTC (permalink / raw)
  To: linux-nfc; +Cc: Krzysztof Kozlowski

g_slist_free_full() already frees entire GSList so calling it with
g_slist_free causes a double free and memory corruption.

This can be seen with Valgrind:

  Invalid read of size 8
    at 0x48E3980: g_slice_free_chain_with_offset (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x122075: snep_core_process_request (snep.c:481)
    by 0x122075: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x12457A: test_snep_read_get_req_frags_client_resp (test-snep-read.c:775)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2B9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2D4: g_test_run (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x10F982: main (test-snep-read.c:960)
   Address 0x501e198 is 8 bytes inside a block of size 16 free'd
    at 0x483DA3F: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x48E3971: g_slice_free_chain_with_offset (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x122068: snep_core_process_request (snep.c:479)
    by 0x122068: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x12457A: test_snep_read_get_req_frags_client_resp (test-snep-read.c:775)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2B9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2D4: g_test_run (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x10F982: main (test-snep-read.c:960)
   Block was alloc'd at
    at 0x483C7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x48CA698: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48E2CF1: g_slice_alloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48E4407: g_slist_append (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x121AC7: snep_core_push_prepare_fragments (snep.c:377)
    by 0x121AC7: near_snep_core_response (snep.c:695)
    by 0x1224DB: near_snep_core_response_with_info (snep.c:779)
    by 0x122E41: test_snep_dummy_req_get (test-snep-read.c:172)
    by 0x121FF3: snep_core_process_request (snep.c:413)
    by 0x121FF3: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x124449: test_snep_read_get_req_frags_client_resp (test-snep-read.c:746)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)

  Invalid free() / delete / delete[] / realloc()
    at 0x483DA3F: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x48E3971: g_slice_free_chain_with_offset (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x122075: snep_core_process_request (snep.c:481)
    by 0x122075: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x12457A: test_snep_read_get_req_frags_client_resp (test-snep-read.c:775)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2B9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2D4: g_test_run (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x10F982: main (test-snep-read.c:960)
   Address 0x501e190 is 0 bytes inside a block of size 16 free'd
    at 0x483DA3F: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x48E3971: g_slice_free_chain_with_offset (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x122068: snep_core_process_request (snep.c:479)
    by 0x122068: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x12457A: test_snep_read_get_req_frags_client_resp (test-snep-read.c:775)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2B9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2D4: g_test_run (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x10F982: main (test-snep-read.c:960)
   Block was alloc'd at
    at 0x483C7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x48CA698: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48E2CF1: g_slice_alloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48E4407: g_slist_append (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x121AC7: snep_core_push_prepare_fragments (snep.c:377)
    by 0x121AC7: near_snep_core_response (snep.c:695)
    by 0x1224DB: near_snep_core_response_with_info (snep.c:779)
    by 0x122E41: test_snep_dummy_req_get (test-snep-read.c:172)
    by 0x121FF3: snep_core_process_request (snep.c:413)
    by 0x121FF3: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x124449: test_snep_read_get_req_frags_client_resp (test-snep-read.c:746)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 src/snep.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/snep.c b/src/snep.c
index 737060139b07..bac93c115cb3 100644
--- a/src/snep.c
+++ b/src/snep.c
@@ -436,7 +436,6 @@ static bool snep_core_process_request(int client_fd,
 
 		g_slist_free_full(snep_data->req->fragments,
 						free_snep_core_fragment);
-		g_slist_free(snep_data->req->fragments);
 
 		g_hash_table_remove(snep_client_hash,
 						GINT_TO_POINTER(client_fd));
@@ -476,7 +475,6 @@ leave_cont:
 		/* No more fragment to send, clean memory */
 		g_slist_free_full(snep_data->req->fragments,
 						free_snep_core_fragment);
-		g_slist_free(snep_data->req->fragments);
 
 		g_hash_table_remove(snep_client_hash,
 						GINT_TO_POINTER(client_fd));
-- 
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [neard][PATCH 4/7] snep: fix double free of GSList
@ 2021-07-16 10:08   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-16 10:08 UTC (permalink / raw)
  To: linux-nfc

[-- Attachment #1: Type: text/plain, Size: 6562 bytes --]

g_slist_free_full() already frees entire GSList so calling it with
g_slist_free causes a double free and memory corruption.

This can be seen with Valgrind:

  Invalid read of size 8
    at 0x48E3980: g_slice_free_chain_with_offset (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x122075: snep_core_process_request (snep.c:481)
    by 0x122075: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x12457A: test_snep_read_get_req_frags_client_resp (test-snep-read.c:775)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2B9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2D4: g_test_run (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x10F982: main (test-snep-read.c:960)
   Address 0x501e198 is 8 bytes inside a block of size 16 free'd
    at 0x483DA3F: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x48E3971: g_slice_free_chain_with_offset (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x122068: snep_core_process_request (snep.c:479)
    by 0x122068: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x12457A: test_snep_read_get_req_frags_client_resp (test-snep-read.c:775)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2B9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2D4: g_test_run (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x10F982: main (test-snep-read.c:960)
   Block was alloc'd at
    at 0x483C7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x48CA698: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48E2CF1: g_slice_alloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48E4407: g_slist_append (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x121AC7: snep_core_push_prepare_fragments (snep.c:377)
    by 0x121AC7: near_snep_core_response (snep.c:695)
    by 0x1224DB: near_snep_core_response_with_info (snep.c:779)
    by 0x122E41: test_snep_dummy_req_get (test-snep-read.c:172)
    by 0x121FF3: snep_core_process_request (snep.c:413)
    by 0x121FF3: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x124449: test_snep_read_get_req_frags_client_resp (test-snep-read.c:746)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)

  Invalid free() / delete / delete[] / realloc()
    at 0x483DA3F: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x48E3971: g_slice_free_chain_with_offset (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x122075: snep_core_process_request (snep.c:481)
    by 0x122075: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x12457A: test_snep_read_get_req_frags_client_resp (test-snep-read.c:775)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2B9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2D4: g_test_run (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x10F982: main (test-snep-read.c:960)
   Address 0x501e190 is 0 bytes inside a block of size 16 free'd
    at 0x483DA3F: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x48E3971: g_slice_free_chain_with_offset (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x122068: snep_core_process_request (snep.c:479)
    by 0x122068: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x12457A: test_snep_read_get_req_frags_client_resp (test-snep-read.c:775)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2B9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2D4: g_test_run (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x10F982: main (test-snep-read.c:960)
   Block was alloc'd at
    at 0x483C7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x48CA698: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48E2CF1: g_slice_alloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48E4407: g_slist_append (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x121AC7: snep_core_push_prepare_fragments (snep.c:377)
    by 0x121AC7: near_snep_core_response (snep.c:695)
    by 0x1224DB: near_snep_core_response_with_info (snep.c:779)
    by 0x122E41: test_snep_dummy_req_get (test-snep-read.c:172)
    by 0x121FF3: snep_core_process_request (snep.c:413)
    by 0x121FF3: near_snep_core_read (snep.c:620)
    by 0x122CE4: test_snep_read_req_common (test-snep-read.c:348)
    by 0x124449: test_snep_read_get_req_frags_client_resp (test-snep-read.c:746)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 src/snep.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/snep.c b/src/snep.c
index 737060139b07..bac93c115cb3 100644
--- a/src/snep.c
+++ b/src/snep.c
@@ -436,7 +436,6 @@ static bool snep_core_process_request(int client_fd,
 
 		g_slist_free_full(snep_data->req->fragments,
 						free_snep_core_fragment);
-		g_slist_free(snep_data->req->fragments);
 
 		g_hash_table_remove(snep_client_hash,
 						GINT_TO_POINTER(client_fd));
@@ -476,7 +475,6 @@ leave_cont:
 		/* No more fragment to send, clean memory */
 		g_slist_free_full(snep_data->req->fragments,
 						free_snep_core_fragment);
-		g_slist_free(snep_data->req->fragments);
 
 		g_hash_table_remove(snep_client_hash,
 						GINT_TO_POINTER(client_fd));
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [linux-nfc] [neard][PATCH 5/7] unit: fix memory leaks in test-snep-read error paths
  2021-07-16 10:08 ` Krzysztof Kozlowski
@ 2021-07-16 10:08   ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-16 10:08 UTC (permalink / raw)
  To: linux-nfc; +Cc: Krzysztof Kozlowski

Cleanup and free memory in error paths in test-snep-read.c.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 unit/test-snep-read.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/unit/test-snep-read.c b/unit/test-snep-read.c
index 0a2010a677e1..3bc1a9fad7df 100644
--- a/unit/test-snep-read.c
+++ b/unit/test-snep-read.c
@@ -131,12 +131,12 @@ static bool test_snep_dummy_req_put(int fd, void *data)
 	records = near_ndef_parse_msg(nfc_data, nfc_data_length, NULL);
 	if (!records) {
 		TEST_SNEP_LOG("\tdummy_req_put parsing ndef failed\n");
-		goto error;
+		goto error_free_nfc_data;
 	}
 
 	if (g_list_length(records) != 1) {
 		TEST_SNEP_LOG("\tdummy_req_put records number mismatch");
-		goto error;
+		goto error_free_records;
 	}
 
 	g_free(nfc_data);
@@ -149,6 +149,10 @@ static bool test_snep_dummy_req_put(int fd, void *data)
 	near_snep_core_response_noinfo(fd, NEAR_SNEP_RESP_SUCCESS);
 	return true;
 
+error_free_records:
+	near_ndef_records_free(records);
+error_free_nfc_data:
+	g_free(nfc_data);
 error:
 	TEST_SNEP_LOG("\tdummy_req_put error!!!\n");
 	return false;
-- 
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [neard][PATCH 5/7] unit: fix memory leaks in test-snep-read error paths
@ 2021-07-16 10:08   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-16 10:08 UTC (permalink / raw)
  To: linux-nfc

[-- Attachment #1: Type: text/plain, Size: 1190 bytes --]

Cleanup and free memory in error paths in test-snep-read.c.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 unit/test-snep-read.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/unit/test-snep-read.c b/unit/test-snep-read.c
index 0a2010a677e1..3bc1a9fad7df 100644
--- a/unit/test-snep-read.c
+++ b/unit/test-snep-read.c
@@ -131,12 +131,12 @@ static bool test_snep_dummy_req_put(int fd, void *data)
 	records = near_ndef_parse_msg(nfc_data, nfc_data_length, NULL);
 	if (!records) {
 		TEST_SNEP_LOG("\tdummy_req_put parsing ndef failed\n");
-		goto error;
+		goto error_free_nfc_data;
 	}
 
 	if (g_list_length(records) != 1) {
 		TEST_SNEP_LOG("\tdummy_req_put records number mismatch");
-		goto error;
+		goto error_free_records;
 	}
 
 	g_free(nfc_data);
@@ -149,6 +149,10 @@ static bool test_snep_dummy_req_put(int fd, void *data)
 	near_snep_core_response_noinfo(fd, NEAR_SNEP_RESP_SUCCESS);
 	return true;
 
+error_free_records:
+	near_ndef_records_free(records);
+error_free_nfc_data:
+	g_free(nfc_data);
 error:
 	TEST_SNEP_LOG("\tdummy_req_put error!!!\n");
 	return false;
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [linux-nfc] [neard][PATCH 6/7] unit: fix record memory leak in test-snep-read
  2021-07-16 10:08 ` Krzysztof Kozlowski
@ 2021-07-16 10:08   ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-16 10:08 UTC (permalink / raw)
  To: linux-nfc; +Cc: Krzysztof Kozlowski

Instead of open-coding __near_ndef_record_free() with mistakes, use it
directly to fix memory leaks like:

  2 bytes in 1 blocks are definitely lost in loss record 2 of 36
    at 0x483C7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x48CA698: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48E4B3D: g_strndup (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x11CB66: parse_record_header (ndef.c:1122)
    by 0x11CB66: parse_record_header (ndef.c:1029)
    by 0x11E549: near_ndef_parse_msg (ndef.c:2846)
    by 0x122A23: test_snep_dummy_req_put (test-snep-read.c:131)
    by 0x122005: snep_core_process_request (snep.c:397)
    by 0x122005: near_snep_core_read (snep.c:617)
    by 0x123042: test_snep_read_req_common.constprop.0 (test-snep-read.c:352)
    by 0x1234E0: test_snep_read_put_req_ok (test-snep-read.c:500)
    by 0x1234E0: test_snep_read_get_req_ok (test-snep-read.c:644)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2B9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)

  15 bytes in 1 blocks are definitely lost in loss record 13 of 36
    at 0x483ED99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x11E65F: near_ndef_parse_msg (ndef.c:2958)
    by 0x122A23: test_snep_dummy_req_put (test-snep-read.c:131)
    by 0x122005: snep_core_process_request (snep.c:397)
    by 0x122005: near_snep_core_read (snep.c:617)
    by 0x123042: test_snep_read_req_common.constprop.0 (test-snep-read.c:352)
    by 0x1234E0: test_snep_read_put_req_ok (test-snep-read.c:500)
    by 0x1234E0: test_snep_read_get_req_ok (test-snep-read.c:644)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2B9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2D4: g_test_run (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x10F784: main (test-snep-read.c:967)

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 unit/test-snep-read.c | 2 +-
 unit/test-utils.c     | 8 --------
 unit/test-utils.h     | 2 --
 3 files changed, 1 insertion(+), 11 deletions(-)

diff --git a/unit/test-snep-read.c b/unit/test-snep-read.c
index 3bc1a9fad7df..a4df6ec95f8f 100644
--- a/unit/test-snep-read.c
+++ b/unit/test-snep-read.c
@@ -224,7 +224,7 @@ static void test_snep_cleanup(gpointer context, gconstpointer data)
 	__near_snep_core_cleanup();
 
 	if (stored_recd)
-		test_ndef_free_record(stored_recd);
+		__near_ndef_record_free(stored_recd);
 
 	if (ctx->test_recd_msg) {
 		g_free(ctx->test_recd_msg->data);
diff --git a/unit/test-utils.c b/unit/test-utils.c
index fe256561821f..369437421971 100644
--- a/unit/test-utils.c
+++ b/unit/test-utils.c
@@ -20,14 +20,6 @@
 
 #include "test-utils.h"
 
-void test_ndef_free_record(struct near_ndef_record *record)
-{
-	g_free(record->header);
-	g_free(record->type);
-	g_free(record->data);
-	g_free(record);
-}
-
 struct near_ndef_message *test_ndef_create_test_record(const char *str)
 {
 	struct near_ndef_message *ndef;
diff --git a/unit/test-utils.h b/unit/test-utils.h
index c371d566a573..108f2a1fb139 100644
--- a/unit/test-utils.h
+++ b/unit/test-utils.h
@@ -143,8 +143,6 @@ struct near_ndef_record {
 	size_t data_len;
 };
 
-void test_ndef_free_record(struct near_ndef_record *record);
-
 struct near_ndef_message *test_ndef_create_test_record(const char *str);
 
 #endif
-- 
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [neard][PATCH 6/7] unit: fix record memory leak in test-snep-read
@ 2021-07-16 10:08   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-16 10:08 UTC (permalink / raw)
  To: linux-nfc

[-- Attachment #1: Type: text/plain, Size: 3764 bytes --]

Instead of open-coding __near_ndef_record_free() with mistakes, use it
directly to fix memory leaks like:

  2 bytes in 1 blocks are definitely lost in loss record 2 of 36
    at 0x483C7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x48CA698: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48E4B3D: g_strndup (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x11CB66: parse_record_header (ndef.c:1122)
    by 0x11CB66: parse_record_header (ndef.c:1029)
    by 0x11E549: near_ndef_parse_msg (ndef.c:2846)
    by 0x122A23: test_snep_dummy_req_put (test-snep-read.c:131)
    by 0x122005: snep_core_process_request (snep.c:397)
    by 0x122005: near_snep_core_read (snep.c:617)
    by 0x123042: test_snep_read_req_common.constprop.0 (test-snep-read.c:352)
    by 0x1234E0: test_snep_read_put_req_ok (test-snep-read.c:500)
    by 0x1234E0: test_snep_read_get_req_ok (test-snep-read.c:644)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2B9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)

  15 bytes in 1 blocks are definitely lost in loss record 13 of 36
    at 0x483ED99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x11E65F: near_ndef_parse_msg (ndef.c:2958)
    by 0x122A23: test_snep_dummy_req_put (test-snep-read.c:131)
    by 0x122005: snep_core_process_request (snep.c:397)
    by 0x122005: near_snep_core_read (snep.c:617)
    by 0x123042: test_snep_read_req_common.constprop.0 (test-snep-read.c:352)
    by 0x1234E0: test_snep_read_put_req_ok (test-snep-read.c:500)
    by 0x1234E0: test_snep_read_get_req_ok (test-snep-read.c:644)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2B9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2D4: g_test_run (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x10F784: main (test-snep-read.c:967)

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 unit/test-snep-read.c | 2 +-
 unit/test-utils.c     | 8 --------
 unit/test-utils.h     | 2 --
 3 files changed, 1 insertion(+), 11 deletions(-)

diff --git a/unit/test-snep-read.c b/unit/test-snep-read.c
index 3bc1a9fad7df..a4df6ec95f8f 100644
--- a/unit/test-snep-read.c
+++ b/unit/test-snep-read.c
@@ -224,7 +224,7 @@ static void test_snep_cleanup(gpointer context, gconstpointer data)
 	__near_snep_core_cleanup();
 
 	if (stored_recd)
-		test_ndef_free_record(stored_recd);
+		__near_ndef_record_free(stored_recd);
 
 	if (ctx->test_recd_msg) {
 		g_free(ctx->test_recd_msg->data);
diff --git a/unit/test-utils.c b/unit/test-utils.c
index fe256561821f..369437421971 100644
--- a/unit/test-utils.c
+++ b/unit/test-utils.c
@@ -20,14 +20,6 @@
 
 #include "test-utils.h"
 
-void test_ndef_free_record(struct near_ndef_record *record)
-{
-	g_free(record->header);
-	g_free(record->type);
-	g_free(record->data);
-	g_free(record);
-}
-
 struct near_ndef_message *test_ndef_create_test_record(const char *str)
 {
 	struct near_ndef_message *ndef;
diff --git a/unit/test-utils.h b/unit/test-utils.h
index c371d566a573..108f2a1fb139 100644
--- a/unit/test-utils.h
+++ b/unit/test-utils.h
@@ -143,8 +143,6 @@ struct near_ndef_record {
 	size_t data_len;
 };
 
-void test_ndef_free_record(struct near_ndef_record *record);
-
 struct near_ndef_message *test_ndef_create_test_record(const char *str);
 
 #endif
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [linux-nfc] [neard][PATCH 7/7] unit: fix records GList memory leak in test-snep-read
  2021-07-16 10:08 ` Krzysztof Kozlowski
@ 2021-07-16 10:08   ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-16 10:08 UTC (permalink / raw)
  To: linux-nfc; +Cc: Krzysztof Kozlowski

The test_snep_dummy_req_put() stores one record in global stored_recd
pointer, so the GList itself should be freed.  This fixes Valgrind
warning:

  24 bytes in 1 blocks are definitely lost in loss record 21 of 30
    at 0x483C7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x48CA698: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48E2CF1: g_slice_alloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48BFF07: g_list_append (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x11E68A: near_ndef_parse_msg (ndef.c:2964)
    by 0x122A23: test_snep_dummy_req_put (test-snep-read.c:131)
    by 0x122005: snep_core_process_request (snep.c:397)
    by 0x122005: near_snep_core_read (snep.c:617)
    by 0x123042: test_snep_read_req_common.constprop.0 (test-snep-read.c:352)
    by 0x1234E0: test_snep_read_put_req_ok (test-snep-read.c:500)
    by 0x1234E0: test_snep_read_get_req_ok (test-snep-read.c:644)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2B9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 unit/test-snep-read.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/unit/test-snep-read.c b/unit/test-snep-read.c
index a4df6ec95f8f..2e977f749610 100644
--- a/unit/test-snep-read.c
+++ b/unit/test-snep-read.c
@@ -142,6 +142,7 @@ static bool test_snep_dummy_req_put(int fd, void *data)
 	g_free(nfc_data);
 
 	stored_recd = records->data;
+	g_list_free(records);
 
 	TEST_SNEP_LOG("\t\tdummy_req_put STORED REC data=%p length=%zu\n",
 			stored_recd->data, stored_recd->data_len);
-- 
2.27.0
_______________________________________________
Linux-nfc mailing list -- linux-nfc@lists.01.org
To unsubscribe send an email to linux-nfc-leave@lists.01.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [neard][PATCH 7/7] unit: fix records GList memory leak in test-snep-read
@ 2021-07-16 10:08   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2021-07-16 10:08 UTC (permalink / raw)
  To: linux-nfc

[-- Attachment #1: Type: text/plain, Size: 1858 bytes --]

The test_snep_dummy_req_put() stores one record in global stored_recd
pointer, so the GList itself should be freed.  This fixes Valgrind
warning:

  24 bytes in 1 blocks are definitely lost in loss record 21 of 30
    at 0x483C7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x48CA698: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48E2CF1: g_slice_alloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48BFF07: g_list_append (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x11E68A: near_ndef_parse_msg (ndef.c:2964)
    by 0x122A23: test_snep_dummy_req_put (test-snep-read.c:131)
    by 0x122005: snep_core_process_request (snep.c:397)
    by 0x122005: near_snep_core_read (snep.c:617)
    by 0x123042: test_snep_read_req_common.constprop.0 (test-snep-read.c:352)
    by 0x1234E0: test_snep_read_put_req_ok (test-snep-read.c:500)
    by 0x1234E0: test_snep_read_get_req_ok (test-snep-read.c:644)
    by 0x48ECDCD: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ECBCA: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)
    by 0x48ED2B9: g_test_run_suite (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6600.1)

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 unit/test-snep-read.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/unit/test-snep-read.c b/unit/test-snep-read.c
index a4df6ec95f8f..2e977f749610 100644
--- a/unit/test-snep-read.c
+++ b/unit/test-snep-read.c
@@ -142,6 +142,7 @@ static bool test_snep_dummy_req_put(int fd, void *data)
 	g_free(nfc_data);
 
 	stored_recd = records->data;
+	g_list_free(records);
 
 	TEST_SNEP_LOG("\t\tdummy_req_put STORED REC data=%p length=%zu\n",
 			stored_recd->data, stored_recd->data_len);
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-07-16 10:09 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-16 10:08 [linux-nfc] [neard][PATCH 0/7] Fixes for more memory issues Krzysztof Kozlowski
2021-07-16 10:08 ` Krzysztof Kozlowski
2021-07-16 10:08 ` [linux-nfc] [neard][PATCH 1/7] snep: do not open-code freeing ndef message Krzysztof Kozlowski
2021-07-16 10:08   ` Krzysztof Kozlowski
2021-07-16 10:08 ` [linux-nfc] [neard][PATCH 2/7] unit: fix memory leaks in test-ndef-build Krzysztof Kozlowski
2021-07-16 10:08   ` Krzysztof Kozlowski
2021-07-16 10:08 ` [linux-nfc] [neard][PATCH 3/7] snep: remove useless NULL-ify of local pointer variable Krzysztof Kozlowski
2021-07-16 10:08   ` Krzysztof Kozlowski
2021-07-16 10:08 ` [linux-nfc] [neard][PATCH 4/7] snep: fix double free of GSList Krzysztof Kozlowski
2021-07-16 10:08   ` Krzysztof Kozlowski
2021-07-16 10:08 ` [linux-nfc] [neard][PATCH 5/7] unit: fix memory leaks in test-snep-read error paths Krzysztof Kozlowski
2021-07-16 10:08   ` Krzysztof Kozlowski
2021-07-16 10:08 ` [linux-nfc] [neard][PATCH 6/7] unit: fix record memory leak in test-snep-read Krzysztof Kozlowski
2021-07-16 10:08   ` Krzysztof Kozlowski
2021-07-16 10:08 ` [linux-nfc] [neard][PATCH 7/7] unit: fix records GList " Krzysztof Kozlowski
2021-07-16 10:08   ` Krzysztof Kozlowski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.