-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I have been trying to plug a memory leak in CVS m4:
$ m4 -m load include(forloop.m4)dnl for a forloop macro to make the leak more obvious forloop(i,1,5000,`unload(gnu)load(gnu)regexp(123,\(4\)?2)') Part of the leak was libltdl's fault, and I sent a patch accordingly. But what caught my attention was the difference in behavior on whether the 'gnu' module is dlpreload'd or not. When a dynamic library is used, the library's _init and _fini functions get run, and all exported variables get put back to their original initialization value after unloading and reloading. But when the library is used preloaded, the storage for all the variables of the library only gets initialized once at program startup, and not on the conceptual reload. This caused a core dump when I freed a library global before closing the module, but did not zero the variable, and on reloading it, dereferenced the variable because it was not NULL. I don't know if there is anything that dlpreload can do about this (because it is not just the exported variables that preserve state, but all variables private to the library; it would take something like an ELF reader to determine where the .data and .bss sections of the library live to reinitialize them properly), so it may just be worth documenting that when using libltdl, you must ensure that your library can cope with variables inheriting state across an unload and reload. In m4's case, it just meant that I had to explicitly zero memory as I freed it before unload, because I couldn't rely on the unload/reload sequence to reset that memory. - -- Life is short - so eat dessert first! Eric Blake [EMAIL PROTECTED] -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.1 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD4DBQFFIlOM84KuGfSFAYARAktSAJj0UDGP5qW3DT8It6+K2NMxvZREAKCxl1LK /2igN9im/Ol90NlYxz0NNA== =N7Ps -----END PGP SIGNATURE----- _______________________________________________ http://lists.gnu.org/mailman/listinfo/libtool
