File indexing completed on 2024-04-21 05:41:32

0001 #include <cstdio>
0002 #include <cstdlib>
0003 #include <cstring>
0004 
0005 #include <dlfcn.h>
0006 
0007 extern "C" {
0008 extern void allocFromLib(bool leak)
0009 {
0010     fprintf(stderr, "malloc address: %p\n", dlsym(RTLD_NEXT, "malloc"));
0011     fprintf(stderr, "free address: %p\n", dlsym(RTLD_NEXT, "free"));
0012 
0013     auto ret = strdup("my long string that I want to copy");
0014     fprintf(stderr, "string is: %s\n", ret);
0015     if (!leak) {
0016         free(ret);
0017     }
0018 
0019     auto p = malloc(10);
0020     fprintf(stderr, "p = %p\n", p);
0021 
0022     if (!leak) {
0023         free(p);
0024     }
0025 }
0026 }