Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leaks in multi_client_server.c:213 #132

Closed
LancyRiver opened this issue Jan 4, 2023 · 3 comments
Closed

Memory leaks in multi_client_server.c:213 #132

LancyRiver opened this issue Jan 4, 2023 · 3 comments

Comments

@LancyRiver
Copy link

Hello, there is a memory leak in lib60870/lib60870-C/examples/multi_client_server/multi_client_server.c:213.

In the directory lib60870/lib60870-C/examples/multi_client_server,this pointer newAsdu in multi_client_server.c:213 is not freed in the end. It will cause memory leaks.

steps to reproduce:
I used gcc 9.4 and AddressSanitizer (export CFLAGS="-g -fsanitize=address" LDFLAGS="-fsanitize=address" before make) to build lib60870/lib60870-C/examples/multi_client_server.
Run this program multi_client_server.
Press the button Ctrl+C to terminate the program multi_client_server.

ASAN Output

$ ./multi_client_server    
^C
=================================================================
==11375==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 296 byte(s) in 1 object(s) allocated from:
    #0 0x7fa9a372d808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
    #1 0x55956bd32773 in Memory_malloc src/hal/memory/lib_memory.c:33
    #2 0x55956bd25f59 in CS101_ASDU_create src/iec60870/cs101/cs101_asdu.c:90
    #3 0x55956bd1a052 in main /home/saltf1sh/target/lib60870/lib60870-C/examples/multi_client_server/multi_client_server.c:213
    #4 0x7fa9a342f0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2)

SUMMARY: AddressSanitizer: 296 byte(s) leaked in 1 allocation(s).
@LancyRiver
Copy link
Author

I think adding this line of code to multi_client_server.c:251 can fix it.
CS101_ASDU_destroy(newAsdu);

@mzillgith
Copy link
Contributor

Hi.
Thank you for the hint.
I changed the example so it doesn't show the memory leak.

@LancyRiver
Copy link
Author

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants