From: Gary V. Vaughan Date: Fri, 21 Sep 2001 17:48:07 +0000 (+0000) Subject: * libltdl/ltdl.c: Added support for dmalloc, and uncovered some X-Git-Tag: release-1-4-3~50 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=717f34db007bb5bdf1ac23102f5b4e3499bfa91e;p=thirdparty%2Flibtool.git * libltdl/ltdl.c: Added support for dmalloc, and uncovered some memory bugs as a result. --- diff --git a/ChangeLog b/ChangeLog index febbfc01e..bd7cfe8a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2001-09-21 Gary V. Vaughan + + * libltdl/ltdl.c: Added support for dmalloc, and uncovered some + memory bugs as a result. + 2001-09-13 Gary V. Vaughan * ltmain.in (exec_cmd): Don't overquote or we end up with this: diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c index 19293f4d0..c08d16511 100644 --- a/libltdl/ltdl.c +++ b/libltdl/ltdl.c @@ -94,6 +94,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA #include "ltdl.h" +#if WITH_DMALLOC +# include +#endif + @@ -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 @@ -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);