From a59a69d5e5a389390140c8222e7a02d6c50dcedb Mon Sep 17 00:00:00 2001 From: Guido Casati Date: Tue, 6 Aug 2024 15:21:29 +0200 Subject: [PATCH] Fix strdup-related memory leak in nr-softmodem * strdup is returning a malloced string which needs to be freed after use > Direct leak of 90 byte(s) in 1 object(s) allocated from: > 0 0x7ffff745b9a7 in __interceptor_strdup ../../../../src/libsanitizer/asan/asan_interceptors.cpp:454 > 1 0x5555591598a3 in main /executables/nr-softmodem.c:667 > 2 0x7ffff5e29d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 --- executables/nr-softmodem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c index b188ead832..7a141be471 100644 --- a/executables/nr-softmodem.c +++ b/executables/nr-softmodem.c @@ -664,7 +664,8 @@ int main( int argc, char **argv ) { #define PACKAGE_VERSION "UNKNOWN-EXPERIMENTAL" #endif // strdup to put the sring in the core file for post mortem identification - LOG_I(HW, "Version: %s\n", strdup(PACKAGE_VERSION)); + char *pckg = strdup(PACKAGE_VERSION); + LOG_I(HW, "Version: %s\n", pckg); // don't create if node doesn't connect to RRC/S1/GTP const ngran_node_t node_type = get_node_type(); @@ -819,6 +820,7 @@ int main( int argc, char **argv ) { RC.ru[ru_id]->ifdevice.trx_end_func(&RC.ru[ru_id]->ifdevice); } + free(pckg); logClean(); printf("Bye.\n"); return 0;