]> git.ipfire.org Git - thirdparty/libtool.git/commitdiff
* libltdl/ltdl.c: Added support for dmalloc, and uncovered some
authorGary V. Vaughan <gary@gnu.org>
Fri, 21 Sep 2001 17:48:07 +0000 (17:48 +0000)
committerGary V. Vaughan <gary@gnu.org>
Fri, 21 Sep 2001 17:48:07 +0000 (17:48 +0000)
memory bugs as a result.

ChangeLog
libltdl/ltdl.c

index febbfc01e8e2b96418ab1d90104f96b038b3b81b..bd7cfe8a46a141648ab93a55df13925b68dc4116 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2001-09-21  Gary V. Vaughan  <gary@gnu.org>
+
+       * libltdl/ltdl.c: Added support for dmalloc, and uncovered some
+       memory bugs as a result.
+
 2001-09-13  Gary V. Vaughan  <gary@gnu.org>
 
        * ltmain.in (exec_cmd): Don't overquote or we end up with this:
index 19293f4d0942442c5418684f7aaac764b61311a0..c08d16511848d2a081683c6f4095ef885f7f0e4f 100644 (file)
@@ -94,6 +94,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 
 #include "ltdl.h"
 
+#if WITH_DMALLOC
+#  include <dmalloc.h>
+#endif
+
 
 
 \f
@@ -166,6 +170,18 @@ LT_GLOBAL_DATA void   (*lt_dlfree) LT_PARAMS((lt_ptr ptr))
 
 /* The following macros reduce the amount of typing needed to cast
    assigned memory.  */
+#if WITH_DMALLOC
+
+#define LT_DLMALLOC(tp, n)     ((tp *) xmalloc ((n) * sizeof(tp)))
+#define LT_DLREALLOC(tp, p, n) ((tp *) xrealloc ((p), (n) * sizeof(tp)))
+#define LT_DLFREE(p)                                           \
+       LT_STMT_START { if (p) (p) = (xfree (p), (lt_ptr) 0); } LT_STMT_END
+
+#define LT_EMALLOC(tp, n)      ((tp *) xmalloc ((n) * sizeof(tp)))
+#define LT_EREALLOC(tp, p, n)  ((tp *) xrealloc ((p), (n) * sizeof(tp)))
+
+#else
+
 #define LT_DLMALLOC(tp, n)     ((tp *) lt_dlmalloc ((n) * sizeof(tp)))
 #define LT_DLREALLOC(tp, p, n) ((tp *) rpl_realloc ((p), (n) * sizeof(tp)))
 #define LT_DLFREE(p)                                           \
@@ -174,8 +190,10 @@ LT_GLOBAL_DATA void   (*lt_dlfree) LT_PARAMS((lt_ptr ptr))
 #define LT_EMALLOC(tp, n)      ((tp *) lt_emalloc ((n) * sizeof(tp)))
 #define LT_EREALLOC(tp, p, n)  ((tp *) lt_erealloc ((p), (n) * sizeof(tp)))
 
+#endif
+
 #define LT_DLMEM_REASSIGN(p, q)                        LT_STMT_START { \
-       if ((p) != (q)) { lt_dlfree (p); (p) = (q); (q) = 0; }  \
+       if ((p) != (q)) { if (p) lt_dlfree (p); (p) = (q); (q) = 0; }   \
                                                } LT_STMT_END
 
 \f
@@ -881,10 +899,10 @@ char *
 lt_estrdup (str)
      const char *str;
 {
-  char *dup = strdup (str);
-  if (LT_STRLEN (str) && !dup)
+  char *copy = strdup (str);
+  if (LT_STRLEN (str) && !copy)
     LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
-  return dup;
+  return copy;
 }
 
 
@@ -1685,9 +1703,17 @@ static   int     lt_argz_insert        LT_PARAMS((char **pargz,
 static int     lt_argz_insertinorder LT_PARAMS((char **pargz,
                                                 size_t *pargz_len,
                                                 const char *entry));
+static int     lt_argz_insertdir     LT_PARAMS((char **pargz,
+                                                size_t *pargz_len,
+                                                const char *dirnam,
+                                                struct dirent *dp));
 static int     lt_dlpath_insertdir   LT_PARAMS((char **ppath,
                                                 char *before,
                                                 const char *dir));
+static int     list_files_by_dir     LT_PARAMS((const char *dirnam,
+                                                char **pargz,
+                                                size_t *pargz_len));
+static int     file_not_found        LT_PARAMS((void));
 
 static char           *user_search_path= 0;
 static lt_dlloader    *loaders         = 0;
@@ -2139,10 +2165,10 @@ foreach_dirinpath (search_path, base_name, func, data1, data2)
   int   result         = 0;
   int   filenamesize   = 0;
   int   lenbase        = LT_STRLEN (base_name);
-  size_t argz_len      = 0;
-  char * argz          = 0;
-  char * filename      = 0;
-  char * canonical     = 0;
+  int  argz_len        = 0;
+  char *argz           = 0;
+  char *filename       = 0;
+  char *canonical      = 0;
 
   LT_DLMUTEX_LOCK ();
 
@@ -2923,7 +2949,6 @@ lt_dlopenext (filename)
   char *       ext             = 0;
   int          len;
   int          errors          = 0;
-  int          file_found      = 1; /* until proven otherwise */
 
   if (!filename)
     {
@@ -3285,6 +3310,9 @@ lt_dlclose (handle)
       errors += handle->loader->module_close (data, handle->module);
       errors += unload_deplibs(handle);
 
+      /* It is up to the callers to free the data itself.  */
+      LT_DLFREE (handle->caller_data);
+
       LT_DLFREE (handle->info.filename);
       LT_DLFREE (handle->info.name);
       LT_DLFREE (handle);