talloc: Add a warning about talloc_autofree_context() and dlclose()
authorVolker Lendecke <vl@samba.org>
Fri, 24 Sep 2010 17:20:06 +0000 (19:20 +0200)
committerVolker Lendecke <vl@samba.org>
Sat, 25 Sep 2010 00:21:42 +0000 (17:21 -0700)
lib/talloc/talloc.h
lib/talloc/talloc_guide.txt

index 187d7e781672c5916918b710ecdb0377a15675b0..8b9ade202e52abbc25a9f8ee6e61d352cd98d133 100644 (file)
@@ -972,6 +972,15 @@ int talloc_unlink(const void *context, void *ptr);
  * which will be automatically freed on program exit. This can be used
  * to reduce the noise in memory leak reports.
  *
+ * Never use this in code that might be used in objects loaded with
+ * dlopen and unloaded with dlclose. talloc_autofree_context()
+ * internally uses atexit(3). Some platforms like modern Linux handles
+ * this fine, but for example FreeBSD does not deal well with dlopen()
+ * and atexit() used simultaneously: dlclose() does not clean up the
+ * list of atexit-handlers, so when the program exits the code that
+ * was registered from within talloc_autofree_context() is gone, the
+ * program crashes at exit.
+ *
  * @return              A talloc context, NULL on error.
  */
 void *talloc_autofree_context(void);
index a79fd03a831d13394db8bac5643d9c48dacf1fa1..f29b1d699a83b6891d78ed7456ce19b16d8034c3 100644 (file)
@@ -74,6 +74,19 @@ without proper synchronization ;
 shouldn't be used by several threads simultaneously without  
 synchronization.
 
+talloc and shared objects
+-------------------------
+
+talloc can be used in shared objects. Special care needs to be taken
+to never use talloc_autofree_context() in code that might be loaded
+with dlopen() and unloaded with dlclose(), as talloc_autofree_context()
+internally uses atexit(3). Some platforms like modern Linux handles
+this fine, but for example FreeBSD does not deal well with dlopen()
+and atexit() used simultaneously: dlclose() does not clean up the list
+of atexit-handlers, so when the program exits the code that was
+registered from within talloc_autofree_context() is gone, the program
+crashes at exit.
+
 
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 (type *)talloc(const void *context, type);