开发者

C --> malloc --> dlsym

I have used dlsym() to invoke my version of malloc, instead of the default library malloc:

 lt_malloc = (void*(*)(size_t))dlsym(RTLD_NEXT, "malloc");
 TRACE((stderr, "initialize: lt_mall开发者_Python百科oc=%p\n", lt_malloc));
 if (!lt_malloc) {
     fprintf(stderr, "LeakTracer: could not resolve 'malloc' in 'libc.so': %s\n", dlerror());
     exit(1);
 }

Now after certain time, may be a timer or so, i want to revert back to the original version of malloc (libc library malloc). How can i do that?

Thanks in advance.


Does the above code mean 1) you have called your malloc also malloc? 2) or that you assign the libc malloc to lt_malloc?

The code above suggests that lt_malloc is the libc malloc so the "original" malloc. Well you than probably have some either some macros or a function

So then you switch as easily as my_malloc = libc_malloc my_malloc = my_debug_malloc

and you just call my_malloc

If that is not helpful please explain the posted code and what you expect at "ente codde here"


You should rather use dlopen on the library containing your malloc function and use the handle from dlopen as a first argument to dlsym.

Alternatively, you can use LD_PRELOAD.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜