I download the example.
admin@dev:~/collect-v2/clients/cclient$ wget https://raw.githubusercontent.com/zhaojh329/libuwsc/master/example/example.c
--2020-01-08 14:39:29-- https://raw.githubusercontent.com/zhaojh329/libuwsc/master/example/example.c
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.52.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.52.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4317 (4.2K) [text/plain]
Saving to: ‘example.c’
example.c 100%[=====================================================================================================================>] 4.22K --.-KB/s in 0.002s
2020-01-08 14:39:29 (2.69 MB/s) - ‘example.c’ saved [4317/4317]
I compile it.
admin@dev:~/collect-v2/clients/cclient$ gcc -I/usr/local/include/uwsc -I/usr/include/json-c -I/usr/local/include -L/usr/local/lib -L/usr/local/lib/uwsc -lpthread -ljson-c -lev -luwsc -o example example.c
I run the program and valgrind using -u ws://localhost/ws
You can see there are no memory leaks reported by valgrind.
admin@dev:~/collect-v2/clients/cclient$ valgrind --leak-check=full ./example -u ws://localhost/ws
==3970== Memcheck, a memory error detector
==3970== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==3970== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright info
==3970== Command: ./example -u ws://localhost/ws
==3970==
2020/01/08 14:40:35 (example.c:141) Libuwsc: 3.3.2
2020/01/08 14:40:36 (example.c:147) Start connect...
2020/01/08 14:40:36 (example.c:91) onerror:2: Invalid header
==3970==
==3970== HEAP SUMMARY:
==3970== in use at exit: 1,016 bytes in 6 blocks
==3970== total heap usage: 66 allocs, 60 frees, 43,855 bytes allocated
==3970==
==3970== LEAK SUMMARY:
==3970== definitely lost: 0 bytes in 0 blocks
==3970== indirectly lost: 0 bytes in 0 blocks
==3970== possibly lost: 0 bytes in 0 blocks
==3970== still reachable: 1,016 bytes in 6 blocks
==3970== suppressed: 0 bytes in 0 blocks
==3970== Reachable blocks (those to which a pointer was found) are not shown.
==3970== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==3970==
==3970== For counts of detected and suppressed errors, rerun with: -v
==3970== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
I run the program using an SSL URL and valgrind using -u wss://localhost/ws
You can see the program has a memory leak from libuwsc! Can you fix this please?
admin@dev:~/collect-v2/clients/cclient$ valgrind --leak-check=full ./example -u wss://localhost/ws
==3971== Memcheck, a memory error detector
==3971== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==3971== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright info
==3971== Command: ./example -u wss://localhost/ws
==3971==
2020/01/08 14:40:40 (example.c:141) Libuwsc: 3.3.2
2020/01/08 14:40:40 (example.c:147) Start connect...
2020/01/08 14:40:41 (ssl.c:141) (null)
2020/01/08 14:40:41 (example.c:91) onerror:7: ssl handshake failed
==3971==
==3971== HEAP SUMMARY:
==3971== in use at exit: 162,494 bytes in 2,922 blocks
==3971== total heap usage: 4,628 allocs, 1,706 frees, 370,000 bytes allocated
==3971==
==3971== 73,990 (824 direct, 73,166 indirect) bytes in 1 blocks are definitely lost in loss record 296 of 296
==3971== at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==3971== by 0x61FDC87: CRYPTO_malloc (in /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2)
==3971== by 0x5F5E2EF: SSL_new (in /usr/lib/x86_64-linux-gnu/libssl.so.1.0.2)
==3971== by 0x5473783: uwsc_ssl_init (in /usr/local/lib/libuwsc.so.3.3.2)
==3971== by 0x54715FC: uwsc_init (in /usr/local/lib/libuwsc.so.3.3.2)
==3971== by 0x54716A3: uwsc_new (in /usr/local/lib/libuwsc.so.3.3.2)
==3971== by 0x109173: main (in /home/admin/collect-v2/clients/cclient/example)
==3971==
==3971== LEAK SUMMARY:
==3971== definitely lost: 824 bytes in 1 blocks
==3971== indirectly lost: 73,166 bytes in 37 blocks
==3971== possibly lost: 0 bytes in 0 blocks
==3971== still reachable: 88,504 bytes in 2,884 blocks
==3971== suppressed: 0 bytes in 0 blocks
==3971== Reachable blocks (those to which a pointer was found) are not shown.
==3971== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==3971==
==3971== For counts of detected and suppressed errors, rerun with: -v
==3971== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)