diff options
| author | Alexander Barton <alex@barton.de> | 2020-02-15 14:56:07 +0100 |
|---|---|---|
| committer | Alexander Barton <alex@barton.de> | 2020-02-15 14:56:07 +0100 |
| commit | 8d173a33286f47ac5678a8ce8cdd756295342cb1 (patch) | |
| tree | f665312609bf3b7176f7d522a64b2ce5ab8511e8 | |
| parent | e7cb9b1a001a97b1edf0e862808cbd0be5264a7a (diff) | |
| download | ngircd-8d173a33286f47ac5678a8ce8cdd756295342cb1.tar.gz ngircd-8d173a33286f47ac5678a8ce8cdd756295342cb1.zip | |
Fix memory leak in portabtest Check_strtok_r()
Fix the following Clang "LeakSanitizer" error (which isn't quite
relevant in this test program, but anyway):
ERROR: LeakSanitizer: detected memory leaks
Direct leak of 7 byte(s) in 1 object(s) allocated from:
#0 0x7f8c4d022810 in strdup (/lib/x86_64-linux-gnu/libasan.so.5+0x3a810)
#1 0x5601a801491a in Check_strtok_r (/net/arthur/home/alex/Develop/ngIRCd/ngIRCd.git/src/portab/portabtest+0x291a)
#2 0x5601a8014d77 in main (/net/arthur/home/alex/Develop/ngIRCd/ngIRCd.git/src/portab/portabtest+0x2d77)
#3 0x7f8c4c69009a in __libc_start_main ../csu/libc-start.c:308
SUMMARY: AddressSanitizer: 7 byte(s) leaked in 1 allocation(s).
FAIL: portabtest
| -rw-r--r-- | src/portab/portabtest.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/portab/portabtest.c b/src/portab/portabtest.c index e7b0dcc8..5ad37b99 100644 --- a/src/portab/portabtest.c +++ b/src/portab/portabtest.c @@ -104,9 +104,10 @@ Check_strlcat(void) static void Check_strtok_r(void) { - char *ptr, *last; + char *str, *ptr, *last; ptr = strdup("12,abc"); + str = ptr; ptr = strtok_r(ptr, ",", &last); if (!ptr) @@ -123,6 +124,8 @@ Check_strtok_r(void) ptr = strtok_r(NULL, ",", &last); if (ptr) Panic("strtok_r result #3"); + + free(str); } #ifdef PROTOTYPES |