Anope IRC Services

Anope Development => Modules => Topic started by: coolvibe on March 13, 2006, 01:49:20 PM

Title: boehm gc and modules
Post by: coolvibe on March 13, 2006, 01:49:20 PM
Hi,

I'm trying to wire in the Boehm garbage collector into anope to be able to find leaks in my module code. I tried substituting the system malloc with the GC malloc with some clever C preprocessor hacks, but it crashes horribly.

What I do is this:
(in services.h somewhere near the top)
Code: [Select]

#ifdef HAVE_BOEHM_GC
#include <gc/gc.h>
#undef malloc
#undef free
#undef realloc
#define malloc(x) GC_malloc(x)
#define free(x) GC_free(x)
#define realloc(x,y) GC_realloc(x,y)
#endif


GC_malloc seems to work, but modules seem to crash the rest of anope when they start to use GC_realloc and GC_free.

Who has done this succesfully?
Title:
Post by: coolvibe on March 13, 2006, 04:07:55 PM
Oh, I also have a #define for calloc, since I noticed that's used in places as well. It should now be:

Code: [Select]

#ifdef HAVE_BOEHM_GC
#include <gc/gc.h>
#undef malloc
#undef free
#undef realloc
#undef calloc
#define malloc(x) GC_MALLOC(x)
#define free(x) GC_FREE(x)
#define realloc(x,y) GC_REALLOC(x,y)
#define calloc(x,y) GC_MALLOC((x) * (y))
#endif


As you can see, I'm using the GC_* macros (since they are safer to use), but still the same crashes.

If anyone has an idea, please reply :)
Title:
Post by: Trystan Scott Lee on March 13, 2006, 08:03:41 PM
Is Boehm a library that you need to build against? if so changing the header.. (bad in the first place) will not solve anything.

Need to link to their library
Title:
Post by: coolvibe on March 14, 2006, 10:08:53 AM
Linking in the library works fine. (had to futz with the topdir Makefile, and that worked fine).

There's also a way to use malloc/* redirects and LD_PRELOAD, but that doesn't work as well as I'd like on FreeBSD (version 5.something). Boehm GC should be a drop-in replacement for malloc/realloc/free et al. (I mean that you should be able to use GC_MALLOC/GC_REALLOC/GC_FREE wherever one would usually use malloc/realloc/free.

[Edited on 14-3-2006 by coolvibe]

[Edited on 14-3-2006 by coolvibe]