Bug 872577 - Using default resolution for free() instead of libc. r=froydnj
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Wed, 14 Aug 2013 22:12:47 +0200
changeset 142765 94088b6bf1619e7f452f86506bc92f5d3c6b3f63
parent 142764 a5150f990fadcfe5997b15a3d9c53e7293a3db54
child 142766 2766d0ee65c5c54b9594199dde88ab1fee3a93e5
push id32503
push usercholler@mozilla.com
push dateThu, 15 Aug 2013 14:59:51 +0000
treeherdermozilla-inbound@94088b6bf161 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs872577
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 872577 - Using default resolution for free() instead of libc. r=froydnj
toolkit/components/osfile/modules/osfile_unix_back.jsm
--- a/toolkit/components/osfile/modules/osfile_unix_back.jsm
+++ b/toolkit/components/osfile/modules/osfile_unix_back.jsm
@@ -223,20 +223,42 @@
                         /*return */ctypes.int,
                         /*dirp*/   Types.DIR.in_ptr.implementation);
 
        UnixFile.closedir = function closedir(fd) {
          // Detach the finalizer and call |_close_dir|.
          return fd.dispose();
        };
 
-       UnixFile.free =
-         libc.declare("free", ctypes.default_abi,
-                       /*return*/ ctypes.void_t,
-                       /*ptr*/    ctypes.voidptr_t);
+       {
+         // Symbol free() is special.
+         // We override the definition of free() on several platforms.
+         let default_lib = libc;
+         try {
+           // On platforms for which we override free(), nspr defines
+           // a special library name "a.out" that will resolve to the
+           // correct implementation free().
+           default_lib = ctypes.open("a.out");
+
+           UnixFile.free =
+             default_lib.declare("free", ctypes.default_abi,
+             /*return*/ ctypes.void_t,
+             /*ptr*/    ctypes.voidptr_t);
+
+         } catch (ex) {
+           // We don't have an a.out library or a.out doesn't contain free.
+           // Either way, use the ordinary libc free.
+
+           UnixFile.free =
+             libc.declare("free", ctypes.default_abi,
+             /*return*/ ctypes.void_t,
+             /*ptr*/    ctypes.voidptr_t);
+         }
+      }
+
 
        // Other functions
        UnixFile.access =
          declareFFI("access", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_nothing,
                     /*path*/   Types.path,
                     /*mode*/   Types.int);