Globally override malloc in visual c++

后端 未结 7 759
死守一世寂寞
死守一世寂寞 2020-12-06 01:47

I\'m trying to figure out a way to globally override malloc and related functions in visual c++ (2005). My setup is a dll with statically linked runtime library that consist

相关标签:
7条回答
  • 2020-12-06 02:35

    The following is true on Linux, but may be applicable to Win's visual C++ as well.

    1. Malloc funciton is provided by system library glibc. The executable is by default linked against it.

    2. When the program is run, the dynamic loader notices that executable needs malloc function and looks for the first library that provides it.

    3. As glibc is (by default) the last in that list, the library found may not be glibc.

    Unless you have statically linked glibc into the executable, the obvious solution is to link the executable against the library that provides your own malloc, and make sure that it does override the system's one.

    0 讨论(0)
提交回复
热议问题