• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to overload system 'malloc'?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to overload system 'malloc'?


  • Subject: How to overload system 'malloc'?
  • From: Yuri <email@hidden>
  • Date: Sun, 26 Dec 2010 12:16:00 -0800

I am trying to use strdup/free in the environment where 'malloc' and 'free' are overloaded in dynamic library libtcmalloc_minimal.dylib from google-perftools macport.

My program brakes with invalid pointer in 'free' since even though /opt/local/lib/libtcmalloc_minimal.0.dylib is loaded and has 'malloc' but 'strdup' in
/usr/lib/libSystem.B.dylib still uses and old 'malloc' in libSystem.B.dylib.


Someone previously suggested using -Wl,-bind_at_load in link comamnd, but it doesn't help.

What is the correct way to completely overload 'malloc'/'free'?

-- tst.C --
#include <string.h>
#include <stdlib.h>

main() {
char *d = strdup("abc");
free(d);
}

-- link command --
g++ -g -o tst tst.C -L/opt/local/lib -ltcmalloc_minimal

--- error from tst ---
src/tcmalloc.cc:372] Attempt to free invalid pointer: 0x1002a0
Abort trap
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: How to overload system 'malloc'?
      • From: Jonas Maebe <email@hidden>
    • Re: How to overload system 'malloc'?
      • From: Rodrigo Zanatta Silva <email@hidden>
  • Prev by Date: Re: Xcode can't make a snapshot - a fix
  • Next by Date: Re: How to overload system 'malloc'?
  • Previous by thread: Re: Xcode can't make a snapshot - a fix
  • Next by thread: Re: How to overload system 'malloc'?
  • Index(es):
    • Date
    • Thread