[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
110-gary-rationalise-memory-management.patch
From: |
Gary V. Vaughan |
Subject: |
110-gary-rationalise-memory-management.patch |
Date: |
Wed, 31 Mar 2004 17:46:51 +0100 (BST) |
User-agent: |
mailnotify/0.2 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Okay to commit?
This addresses the memory management problems in libltdl brought
to light by the kaffe people.
Cheers,
Gary.
- --
Gary V. Vaughan ())_. address@hidden,gnu.org}
Research Scientist ( '/ http://tkd.kicks-ass.net
GNU Hacker / )= http://www.gnu.org/software/libtool
Technical Author `(_~)_ http://sources.redhat.com/autobook
__________________________________________________________
This patch notification generated by cvsapply version 0.13
http://savannah.gnu.org/projects/cvs-utils
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (Darwin)
iD8DBQFAavX7FRMICSmD1gYRAhapAJ4mhw1EIoLO8E8kNxptkA7MGbQseACfdBXE
j40NVDCEOE9PMoS+R1HO79I=
=qGyD
-----END PGP SIGNATURE-----
Index: ChangeLog
from Gary V. Vaughan <address@hidden>
* libltdl/ltdl.c (closedir): Use free.
(opendir): Use malloc/free.
(LT_DLMALLOC, LT_DLREALLOC, LT_DLFREE, LT_EMALLOC, LT_EREALLOC)
(rpl_strdup, rpl_realloc, lt_estrdup, lt_emalloc, lt_erealloc):
Removed in favour of...
(xstrdup, xmalloc, xrealloc, xfree, DELETE): ...these. Changed
all callers.
(xalloc_die): Report memory failures through lt_dlerror.
(LT_DLMEM_REASSIGN): While redoing memory handling, renamed...
(MEM_REASSIGN): ...to this.
(rpl_argz_append, rpl_argz_create_sep, argz_insert): As part of
the portability layer, these functions no longer use libltdl
facilities.
(free_vars): Factored out.
Reported by Dalibor Topic <address@hidden>
Index: libltdl/ltdl.c
===================================================================
RCS file: /cvsroot/libtool/libtool/libltdl/ltdl.c,v
retrieving revision 1.188
diff -u -p -u -r1.188 ltdl.c
--- libltdl/ltdl.c 24 Mar 2004 04:00:46 -0000 1.188
+++ libltdl/ltdl.c 31 Mar 2004 16:45:48 -0000
@@ -1,5 +1,5 @@
/* ltdl.c -- system independent dlopen wrapper
- Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2004 Free Software Foundation, Inc.
Originally by Thomas Tanner <address@hidden>
This file is part of GNU Libtool.
@@ -157,83 +157,9 @@ Foundation, Inc., 59 Temple Place, Suite
-/* --- MEMORY HANDLING --- */
-
-
-/* These are the functions used internally. In addition to making
- use of the associated function pointers above, they also perform
- error handling. */
-static char *lt_estrdup LT_PARAMS((const char *str));
-static lt_ptr lt_emalloc LT_PARAMS((size_t size));
-static lt_ptr lt_erealloc LT_PARAMS((lt_ptr addr, size_t size));
-
-/* static lt_ptr rpl_realloc LT_PARAMS((lt_ptr ptr, size_t size)); */
-#define rpl_realloc realloc
-
-/* These are the pointers that can be changed by the caller: */
-LT_GLOBAL_DATA lt_ptr (*lt_dlmalloc) LT_PARAMS((size_t size))
- = (lt_ptr (*) LT_PARAMS((size_t))) malloc;
-LT_GLOBAL_DATA lt_ptr (*lt_dlrealloc) LT_PARAMS((lt_ptr ptr, size_t size))
- = (lt_ptr (*) LT_PARAMS((lt_ptr, size_t))) rpl_realloc;
-LT_GLOBAL_DATA void (*lt_dlfree) LT_PARAMS((lt_ptr ptr))
- = (void (*) LT_PARAMS((lt_ptr))) free;
-
-/* 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 *) lt_dlrealloc ((p), (n) * sizeof(tp)))
-#define LT_DLFREE(p) \
- LT_STMT_START { if (p) (p) = (lt_dlfree (p), (lt_ptr) 0); } LT_STMT_END
-
-#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)) { if (p) lt_dlfree (p); (p) = (q); (q) = 0; } \
- } LT_STMT_END
-
-
/* --- REPLACEMENT FUNCTIONS --- */
-#undef strdup
-#define strdup rpl_strdup
-
-static char *strdup LT_PARAMS((const char *str));
-
-static char *
-strdup(str)
- const char *str;
-{
- char *tmp = 0;
-
- if (str)
- {
- tmp = LT_DLMALLOC (char, 1+ strlen (str));
- if (tmp)
- {
- strcpy(tmp, str);
- }
- }
-
- return tmp;
-}
-
-
#if ! HAVE_STRCMP
#undef strcmp
@@ -411,7 +337,7 @@ closedir (entry)
{
assert (entry != (DIR *) NULL);
FindClose (entry->hSearch);
- lt_dlfree ((lt_ptr) entry);
+ free ((lt_ptr) entry);
}
@@ -427,24 +353,23 @@ opendir (path)
assert (path != (char *) NULL);
(void) strncpy (file_specification, path, LT_FILENAME_MAX-1);
(void) strcat (file_specification, "\\");
- entry = LT_DLMALLOC (DIR, sizeof(DIR));
+ entry = (DIR *) malloc (sizeof(DIR));
if (entry != (DIR *) 0)
{
entry->firsttime = TRUE;
entry->hSearch = FindFirstFile (file_specification,
&entry->Win32FindData);
- }
- if (entry->hSearch == INVALID_HANDLE_VALUE)
- {
- (void) strcat (file_specification, "\\*.*");
- entry->hSearch = FindFirstFile (file_specification,
- &entry->Win32FindData);
if (entry->hSearch == INVALID_HANDLE_VALUE)
- {
- LT_DLFREE (entry);
- return (DIR *) 0;
- }
+ {
+ (void) strcat (file_specification, "\\*.*");
+ entry->hSearch = FindFirstFile (file_specification,
+ &entry->Win32FindData);
+ if (entry->hSearch == INVALID_HANDLE_VALUE)
+ {
+ entry = (free (entry), (DIR *) 0);
+ }
+ }
}
return entry;
@@ -479,61 +404,6 @@ readdir (entry)
#endif /* !LT_USE_WINDOWS_DIRENT_EMULATION */
-/* According to Alexandre Oliva <address@hidden>,
- ``realloc is not entirely portable''
- In any case we want to use the allocator supplied by the user without
- burdening them with an lt_dlrealloc function pointer to maintain.
- Instead implement our own version (with known boundary conditions)
- using lt_dlmalloc and lt_dlfree. */
-
-/* #undef realloc
- #define realloc rpl_realloc
-*/
-#if 0
- /* You can't (re)define realloc unless you also (re)define malloc.
- Right now, this code uses the size of the *destination* to decide
- how much to copy. That's not right, but you can't know the size
- of the source unless you know enough about, or wrote malloc. So
- this code is disabled... */
-
-static lt_ptr
-realloc (ptr, size)
- lt_ptr ptr;
- size_t size;
-{
- if (size == 0)
- {
- /* For zero or less bytes, free the original memory */
- if (ptr != 0)
- {
- lt_dlfree (ptr);
- }
-
- return (lt_ptr) 0;
- }
- else if (ptr == 0)
- {
- /* Allow reallocation of a NULL pointer. */
- return lt_dlmalloc (size);
- }
- else
- {
- /* Allocate a new block, copy and free the old block. */
- lt_ptr mem = lt_dlmalloc (size);
-
- if (mem)
- {
- memcpy (mem, ptr, size);
- lt_dlfree (ptr);
- }
-
- /* Note that the contents of PTR are not damaged if there is
- insufficient memory to realloc. */
- return mem;
- }
-}
-#endif
-
#if ! HAVE_ARGZ_APPEND
# define argz_append rpl_argz_append
@@ -561,7 +431,7 @@ argz_append (pargz, pargz_len, buf, buf_
/* Ensure there is enough room to append BUF_LEN. */
argz_len = *pargz_len + buf_len;
- argz = LT_DLREALLOC (char, *pargz, argz_len);
+ argz = (char *) realloc (*pargz, argz_len);
if (!argz)
return ENOMEM;
@@ -599,13 +469,13 @@ argz_create_sep (str, delim, pargz, parg
/* Make a copy of STR, but replacing each occurence of
DELIM with '\0'. */
- argz_len = 1+ LT_STRLEN (str);
+ argz_len = 1+ strlen (str);
if (argz_len)
{
const char *p;
char *q;
- argz = LT_DLMALLOC (char, argz_len);
+ argz = (char *) malloc (argz_len);
if (!argz)
return ENOMEM;
@@ -629,7 +499,7 @@ argz_create_sep (str, delim, pargz, parg
/* If ARGZ_LEN has shrunk to nothing, release ARGZ's memory. */
if (!argz_len)
- LT_DLFREE (argz);
+ argz = (free (argz), (char *) 0);
/* Assign new values. */
*pargz = argz;
@@ -669,10 +539,10 @@ argz_insert (pargz, pargz_len, before, e
--before;
{
- size_t entry_len = 1+ LT_STRLEN (entry);
+ size_t entry_len = 1+ strlen (entry);
size_t argz_len = *pargz_len + entry_len;
size_t offset = before - *pargz;
- char *argz = LT_DLREALLOC (char, *pargz, argz_len);
+ char *argz = (char *) realloc (*pargz, argz_len);
if (!argz)
return ENOMEM;
@@ -847,6 +717,32 @@ static const char sys_search_path[] = LT
+/* --- MEMORY HANDLING --- */
+
+
+/* These pointers are part of the published interface to libltdl,
+ although they are no longer used. */
+LT_GLOBAL_DATA lt_ptr (*lt_dlmalloc) LT_PARAMS((size_t size))
+ = (lt_ptr (*) LT_PARAMS((size_t))) malloc;
+LT_GLOBAL_DATA lt_ptr (*lt_dlrealloc) LT_PARAMS((lt_ptr ptr, size_t size))
+ = (lt_ptr (*) LT_PARAMS((lt_ptr, size_t))) realloc;
+LT_GLOBAL_DATA void (*lt_dlfree) LT_PARAMS((lt_ptr ptr))
+ = (void (*) LT_PARAMS((lt_ptr))) free;
+
+
+static lt_ptr xmalloc LT_PARAMS((size_t n));
+static lt_ptr xrealloc LT_PARAMS((lt_ptr p, size_t n));
+static char *xstrdup LT_PARAMS((const char *string));
+
+#define xfree(p) LT_STMT_START { if (p) free (p); } LT_STMT_END
+#define DELETE(p) \
+ LT_STMT_START { if (p) (p) = (free (p), (lt_ptr) 0); } LT_STMT_END
+#define MEM_REASSIGN(p, q) LT_STMT_START { \
+ if ((p) != (q)) { if (p) free (p); (p) = (q); (q) = 0; } \
+ } LT_STMT_END
+
+
+
/* --- MUTEX LOCKING --- */
@@ -941,7 +837,7 @@ lt_dladderror (diagnostic)
LT_DLMUTEX_LOCK ();
errindex = errorcount - LT_ERROR_MAX;
- temp = LT_EREALLOC (const char *, user_error_strings, 1 + errindex);
+ temp = (const char **) xrealloc (user_error_strings, 1 + errindex);
if (temp)
{
user_error_strings = temp;
@@ -984,37 +880,44 @@ lt_dlseterror (errindex)
return errors;
}
+
+
+/* --- MEMORY MANAGEMENT FUNCTIONS --- */
+
+static void
+xalloc_die (void)
+{
+ LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
+}
+
static lt_ptr
-lt_emalloc (size)
- size_t size;
+xmalloc (size_t n)
{
- lt_ptr mem = lt_dlmalloc (size);
- if (size && !mem)
- LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
- return mem;
+ lt_ptr p;
+ if (! (p = malloc (n)))
+ xalloc_die ();
+ return p;
}
static lt_ptr
-lt_erealloc (addr, size)
- lt_ptr addr;
- size_t size;
+xrealloc (lt_ptr p, size_t n)
{
- lt_ptr mem = lt_dlrealloc (addr, size);
- if (size && !mem)
- LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
- return mem;
+ if (! (p = realloc (p, n)))
+ xalloc_die ();
+ return p;
}
-static char *
-lt_estrdup (str)
- const char *str;
+static lt_ptr
+xclone (const lt_ptr p, size_t s)
{
- char *copy = strdup (str);
- if (LT_STRLEN (str) && !copy)
- LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
- return copy;
+ return memcpy (xmalloc (s), p, s);
}
+static char *
+xstrdup (const char *string)
+{
+ return xclone (string, strlen (string) +1);
+}
@@ -1296,13 +1199,13 @@ sys_wll_open (loader_data, filename)
if (ext)
{
/* FILENAME already has an extension. */
- searchname = lt_estrdup (filename);
+ searchname = xstrdup (filename);
}
else
{
/* Append a `.' to stop Windows from adding an
implicit `.dll' extension. */
- searchname = LT_EMALLOC (char, 2+ LT_STRLEN (filename));
+ searchname = (char *) xmalloc (2+ LT_STRLEN (filename));
if (searchname)
sprintf (searchname, "%s.", filename);
}
@@ -1318,7 +1221,7 @@ sys_wll_open (loader_data, filename)
#else
module = LoadLibrary (searchname);
#endif
- LT_DLFREE (searchname);
+ free (searchname);
/* libltdl expects this function to fail if it is unable
to physically load the library. Sadly, LoadLibrary
@@ -1493,13 +1396,12 @@ sys_dld_open (loader_data, filename)
lt_user_data loader_data;
const char *filename;
{
- lt_module module = strdup (filename);
+ lt_module module = xstrdup (filename);
if (dld_link (filename) != 0)
{
LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN));
- LT_DLFREE (module);
- module = 0;
+ DELETE (module);
}
return module;
@@ -1519,7 +1421,7 @@ sys_dld_close (loader_data, module)
}
else
{
- LT_DLFREE (module);
+ DELETE (module);
}
return errors;
@@ -1939,7 +1841,7 @@ presym_free_symlists ()
lt_dlsymlists_t *tmp = lists;
lists = lists->next;
- LT_DLFREE (tmp);
+ free (tmp);
}
preloaded_symbols = 0;
@@ -1976,7 +1878,7 @@ presym_add_symlist (preloaded)
lists = lists->next;
}
- tmp = LT_EMALLOC (lt_dlsymlists_t, 1);
+ tmp = (lt_dlsymlists_t *) xmalloc (sizeof(lt_dlsymlists_t));
if (tmp)
{
memset (tmp, 0, sizeof(lt_dlsymlists_t));
@@ -2123,8 +2025,6 @@ static int find_module LT_PARAMS((
const char *dlname,
const char *old_name,
int installed));
-static int free_vars LT_PARAMS((char *dlname, char *oldname,
- char *libdir, char *deplibs));
static int load_deplibs LT_PARAMS((lt_dlhandle handle,
char *deplibs));
static int trim LT_PARAMS((char **dest,
@@ -2312,7 +2212,7 @@ lt_dlexit ()
++errors;
}
- LT_DLMEM_REASSIGN (loader, next);
+ MEM_REASSIGN (loader, next);
}
loaders = 0;
}
@@ -2378,7 +2278,7 @@ tryall_dlopen (handle, filename)
goto done;
} */
- cur->info.filename = lt_estrdup (filename);
+ cur->info.filename = xstrdup (filename);
if (!cur->info.filename)
{
++errors;
@@ -2405,7 +2305,7 @@ tryall_dlopen (handle, filename)
if (!loader)
{
- LT_DLFREE (cur->info.filename);
+ DELETE (cur->info.filename);
++errors;
goto done;
}
@@ -2447,7 +2347,7 @@ tryall_dlopen_module (handle, prefix, di
/* Allocate memory, and combine DIRNAME and MODULENAME into it.
The PREFIX (if any) is handled below. */
- filename = LT_EMALLOC (char, dirname_len + 1 + filename_len + 1);
+ filename = (char *) xmalloc (dirname_len + 1 + filename_len + 1);
if (!filename)
return 1;
@@ -2466,7 +2366,7 @@ tryall_dlopen_module (handle, prefix, di
++error;
}
- LT_DLFREE (filename);
+ free (filename);
return error;
}
@@ -2527,7 +2427,7 @@ canonicalize_path (path, pcanonical)
assert (path && *path);
assert (pcanonical);
- canonical = LT_EMALLOC (char, 1+ LT_STRLEN (path));
+ canonical = (char *) xmalloc (1+ LT_STRLEN (path));
if (!canonical)
return 1;
@@ -2652,9 +2552,9 @@ foreach_dirinpath (search_path, base_nam
if (lendir +1 +lenbase >= filenamesize)
{
- LT_DLFREE (filename);
+ DELETE (filename);
filenamesize = lendir +1 +lenbase +1; /* "/d" + '/' + "f" + '\0' */
- filename = LT_EMALLOC (char, filenamesize);
+ filename = (char *) xmalloc (filenamesize);
if (!filename)
goto cleanup;
}
@@ -2677,9 +2577,9 @@ foreach_dirinpath (search_path, base_nam
}
cleanup:
- LT_DLFREE (argz);
- LT_DLFREE (canonical);
- LT_DLFREE (filename);
+ xfree (argz);
+ xfree (canonical);
+ xfree (filename);
LT_DLMUTEX_UNLOCK ();
@@ -2710,8 +2610,8 @@ find_file_callback (filename, data1, dat
if (dirend > filename)
*dirend = LT_EOS_CHAR;
- LT_DLFREE (*pdir);
- *pdir = lt_estrdup (filename);
+ xfree (*pdir);
+ *pdir = xstrdup (filename);
is_done = (*pdir == 0) ? -1 : 1;
}
@@ -2795,7 +2695,7 @@ load_deplibs (handle, deplibs)
LT_DLMUTEX_LOCK ();
if (user_search_path)
{
- save_search_path = lt_estrdup (user_search_path);
+ save_search_path = xstrdup (user_search_path);
if (!save_search_path)
goto cleanup;
}
@@ -2836,8 +2736,7 @@ load_deplibs (handle, deplibs)
}
/* restore the old search path */
- LT_DLFREE (user_search_path);
- user_search_path = save_search_path;
+ MEM_REASSIGN (user_search_path, save_search_path);
LT_DLMUTEX_UNLOCK ();
@@ -2847,7 +2746,7 @@ load_deplibs (handle, deplibs)
goto cleanup;
}
- names = LT_EMALLOC (char *, depcount * sizeof (char*));
+ names = (char **) xmalloc (depcount * sizeof (char *));
if (!names)
goto cleanup;
@@ -2876,12 +2775,12 @@ load_deplibs (handle, deplibs)
if (strncmp(p, "-l", 2) == 0)
{
size_t name_len = 3+ /* "lib" */ LT_STRLEN (p + 2);
- name = LT_EMALLOC (char, 1+ name_len);
+ name = (char *) xmalloc (1+ name_len);
if (name)
sprintf (name, "lib%s", p+2);
}
else
- name = lt_estrdup(p);
+ name = strdup(p);
if (!name)
goto cleanup_names;
@@ -2902,7 +2801,7 @@ load_deplibs (handle, deplibs)
{
int j = 0;
- handle->deplibs = (lt_dlhandle*) LT_EMALLOC (lt_dlhandle *, depcount);
+ handle->deplibs = (lt_dlhandle*) xmalloc (sizeof (lt_dlhandle *) *
depcount);
if (!handle->deplibs)
goto cleanup;
@@ -2922,11 +2821,11 @@ load_deplibs (handle, deplibs)
cleanup_names:
for (i = 0; i < depcount; ++i)
{
- LT_DLFREE (names[i]);
+ xfree (names[i]);
}
cleanup:
- LT_DLFREE (names);
+ xfree (names);
#endif
return errors;
@@ -2964,11 +2863,11 @@ trim (dest, str)
size_t len = LT_STRLEN (str);
char *tmp;
- LT_DLFREE (*dest);
+ DELETE (*dest);
if (len > 3 && str[0] == '\'')
{
- tmp = LT_EMALLOC (char, end - str);
+ tmp = (char *) xmalloc (end - str);
if (!tmp)
return 1;
@@ -2985,21 +2884,6 @@ trim (dest, str)
}
static int
-free_vars (dlname, oldname, libdir, deplibs)
- char *dlname;
- char *oldname;
- char *libdir;
- char *deplibs;
-{
- LT_DLFREE (dlname);
- LT_DLFREE (oldname);
- LT_DLFREE (libdir);
- LT_DLFREE (deplibs);
-
- return 0;
-}
-
-static int
try_dlopen (phandle, filename)
lt_dlhandle *phandle;
const char *filename;
@@ -3021,7 +2905,7 @@ try_dlopen (phandle, filename)
/* dlopen self? */
if (!filename)
{
- *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1);
+ *phandle = (lt_dlhandle) xmalloc (sizeof(struct lt_dlhandle_struct));
if (*phandle == 0)
return 1;
@@ -3033,7 +2917,7 @@ try_dlopen (phandle, filename)
if (tryall_dlopen (&newhandle, 0) != 0)
{
- LT_DLFREE (*phandle);
+ DELETE (*phandle);
return 1;
}
@@ -3057,7 +2941,7 @@ try_dlopen (phandle, filename)
{
size_t dirlen = (1+ base_name) - canonical;
- dir = LT_EMALLOC (char, 1+ dirlen);
+ dir = (char *) xmalloc (1+ dirlen);
if (!dir)
{
++errors;
@@ -3070,7 +2954,7 @@ try_dlopen (phandle, filename)
++base_name;
}
else
- LT_DLMEM_REASSIGN (base_name, canonical);
+ MEM_REASSIGN (base_name, canonical);
assert (base_name && *base_name);
@@ -3093,7 +2977,7 @@ try_dlopen (phandle, filename)
int installed = 1;
/* extract the module name from the file name */
- name = LT_EMALLOC (char, ext - base_name + 1);
+ name = (char *) xmalloc (ext - base_name + 1);
if (!name)
{
++errors;
@@ -3168,7 +3052,7 @@ try_dlopen (phandle, filename)
}
line_len = LT_FILENAME_MAX;
- line = LT_EMALLOC (char, line_len);
+ line = (char *) xmalloc (line_len);
if (!line)
{
fclose (file);
@@ -3188,7 +3072,13 @@ try_dlopen (phandle, filename)
that is longer than the initial buffer size. */
while ((line[LT_STRLEN(line) -1] != '\n') && (!feof (file)))
{
- line = LT_DLREALLOC (char, line, line_len *2);
+ line = (char *) xrealloc (line, line_len *2);
+ if (!line)
+ {
+ fclose (file);
+ ++errors;
+ goto cleanup;
+ }
if (!fgets (&line[line_len -1], (int) line_len +1, file))
{
break;
@@ -3249,13 +3139,13 @@ try_dlopen (phandle, filename)
&& dlname
&& (last_libname = strrchr (dlname, ' ')) != 0)
{
- last_libname = lt_estrdup (last_libname + 1);
+ last_libname = strdup (last_libname + 1);
if (!last_libname)
{
++errors;
goto cleanup;
}
- LT_DLMEM_REASSIGN (dlname, last_libname);
+ MEM_REASSIGN (dlname, last_libname);
}
}
@@ -3264,17 +3154,20 @@ try_dlopen (phandle, filename)
}
fclose (file);
- LT_DLFREE (line);
+ free (line);
/* allocate the handle */
- *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1);
+ *phandle = (lt_dlhandle) malloc (sizeof (struct lt_dlhandle_struct));
if (*phandle == 0)
++errors;
if (errors)
{
- free_vars (dlname, old_name, libdir, deplibs);
- LT_DLFREE (*phandle);
+ xfree (dlname);
+ xfree (old_name);
+ xfree (libdir);
+ xfree (deplibs);
+ DELETE (*phandle);
goto cleanup;
}
@@ -3296,10 +3189,14 @@ try_dlopen (phandle, filename)
++errors;
}
- free_vars (dlname, old_name, libdir, deplibs);
+ xfree (dlname);
+ xfree (old_name);
+ xfree (libdir);
+ xfree (deplibs);
+
if (errors)
{
- LT_DLFREE (*phandle);
+ DELETE (*phandle);
goto cleanup;
}
@@ -3311,7 +3208,7 @@ try_dlopen (phandle, filename)
else
{
/* not a libtool module */
- *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1);
+ *phandle = (lt_dlhandle) xmalloc (sizeof(struct lt_dlhandle_struct));
if (*phandle == 0)
{
++errors;
@@ -3345,19 +3242,19 @@ try_dlopen (phandle, filename)
if (!newhandle)
{
- LT_DLFREE (*phandle);
+ DELETE (*phandle);
++errors;
goto cleanup;
}
}
register_handle:
- LT_DLMEM_REASSIGN (*phandle, newhandle);
+ MEM_REASSIGN (*phandle, newhandle);
if ((*phandle)->info.ref_count == 0)
{
(*phandle)->info.ref_count = 1;
- LT_DLMEM_REASSIGN ((*phandle)->info.name, name);
+ MEM_REASSIGN ((*phandle)->info.name, name);
LT_DLMUTEX_LOCK ();
(*phandle)->next = handles;
@@ -3368,9 +3265,9 @@ try_dlopen (phandle, filename)
LT_DLMUTEX_SETERROR (saved_error);
cleanup:
- LT_DLFREE (dir);
- LT_DLFREE (name);
- LT_DLFREE (canonical);
+ xfree (dir);
+ xfree (name);
+ xfree (canonical);
return errors;
}
@@ -3439,7 +3336,7 @@ lt_dlopenext (filename)
}
/* First try appending ARCHIVE_EXT. */
- tmp = LT_EMALLOC (char, len + LT_STRLEN (archive_ext) + 1);
+ tmp = (char *) xmalloc (len + LT_STRLEN (archive_ext) + 1);
if (!tmp)
return 0;
@@ -3454,7 +3351,7 @@ lt_dlopenext (filename)
in the module search path. */
if (handle || ((errors > 0) && !file_not_found ()))
{
- LT_DLFREE (tmp);
+ free (tmp);
return handle;
}
@@ -3462,8 +3359,8 @@ lt_dlopenext (filename)
/* Try appending SHLIB_EXT. */
if (LT_STRLEN (shlib_ext) > LT_STRLEN (archive_ext))
{
- LT_DLFREE (tmp);
- tmp = LT_EMALLOC (char, len + LT_STRLEN (shlib_ext) + 1);
+ free (tmp);
+ tmp = (char *) xmalloc (len + LT_STRLEN (shlib_ext) + 1);
if (!tmp)
return 0;
@@ -3481,7 +3378,7 @@ lt_dlopenext (filename)
with the current error message. */
if (handle || ((errors > 0) && !file_not_found ()))
{
- LT_DLFREE (tmp);
+ free (tmp);
return handle;
}
#endif
@@ -3489,7 +3386,7 @@ lt_dlopenext (filename)
/* Still here? Then we really did fail to locate any of the file
names we tried. */
LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));
- LT_DLFREE (tmp);
+ free (tmp);
return 0;
}
@@ -3590,7 +3487,7 @@ lt_argz_insertdir (pargz, pargz_len, dir
/* Prepend the directory name. */
end_offset = end - dp->d_name;
buf_len = dir_len + 1+ end_offset;
- buf = LT_EMALLOC (char, 1+ buf_len);
+ buf = (char *) xmalloc (1+ buf_len);
if (!buf)
return ++errors;
@@ -3605,7 +3502,7 @@ lt_argz_insertdir (pargz, pargz_len, dir
if (lt_argz_insertinorder (pargz, pargz_len, buf) != 0)
++errors;
- LT_DLFREE (buf);
+ free (buf);
return errors;
}
@@ -3674,7 +3571,7 @@ foreachfile_callback (dirname, data1, da
}
cleanup:
- LT_DLFREE (argz);
+ xfree (argz);
return is_done;
}
@@ -3778,11 +3675,11 @@ lt_dlclose (handle)
errors += unload_deplibs(handle);
/* It is up to the callers to free the data itself. */
- LT_DLFREE (handle->caller_data);
+ xfree (handle->caller_data);
- LT_DLFREE (handle->info.filename);
- LT_DLFREE (handle->info.name);
- LT_DLFREE (handle);
+ xfree (handle->info.filename);
+ xfree (handle->info.name);
+ DELETE (handle);
goto done;
}
@@ -3831,7 +3728,7 @@ lt_dlsym (handle, symbol)
}
else
{
- sym = LT_EMALLOC (char, lensym + LT_SYMBOL_OVERHEAD + 1);
+ sym = (char *) xmalloc (lensym + LT_SYMBOL_OVERHEAD + 1);
if (!sym)
{
LT_DLMUTEX_SETERROR (LT_DLSTRERROR (BUFFER_OVERFLOW));
@@ -3866,7 +3763,7 @@ lt_dlsym (handle, symbol)
{
if (sym != lsym)
{
- LT_DLFREE (sym);
+ free (sym);
}
return address;
}
@@ -3887,7 +3784,7 @@ lt_dlsym (handle, symbol)
address = handle->loader->find_sym (data, handle->module, sym);
if (sym != lsym)
{
- LT_DLFREE (sym);
+ free (sym);
}
return address;
@@ -3932,7 +3829,7 @@ lt_dlpath_insertdir (ppath, before, dir)
assert (!before); /* BEFORE cannot be set without PPATH.
*/
assert (dir); /* Without DIR, don't call this function! */
- *ppath = lt_estrdup (dir);
+ *ppath = strdup (dir);
if (*ppath == 0)
++errors;
@@ -3967,11 +3864,11 @@ lt_dlpath_insertdir (ppath, before, dir)
}
argz_stringify (argz, argz_len, LT_PATHSEP_CHAR);
- LT_DLMEM_REASSIGN (*ppath, argz);
+ MEM_REASSIGN(*ppath, argz);
cleanup:
- LT_DLFREE (canonical);
- LT_DLFREE (argz);
+ xfree (argz); /* argz was allocated by
argz_create_sep */
+ xfree (canonical);
return errors;
}
@@ -4034,7 +3931,7 @@ lt_dlsetsearchpath (search_path)
int errors = 0;
LT_DLMUTEX_LOCK ();
- LT_DLFREE (user_search_path);
+ DELETE (user_search_path);
LT_DLMUTEX_UNLOCK ();
if (!search_path || !LT_STRLEN (search_path))
@@ -4211,7 +4108,8 @@ lt_dlcaller_set_data (key, handle, data)
if (i == n_elements)
{
lt_caller_data *temp
- = LT_DLREALLOC (lt_caller_data, handle->caller_data, 2+ n_elements);
+ = (lt_caller_data *) xrealloc (handle->caller_data,
+ (2+ n_elements) * sizeof(lt_caller_data));
if (!temp)
{
@@ -4287,7 +4185,7 @@ lt_dlloader_add (place, dlloader, loader
}
/* Create a new dlloader node with copies of the user callbacks. */
- node = LT_EMALLOC (lt_dlloader, 1);
+ node = (lt_dlloader *) xmalloc (sizeof(lt_dlloader));
if (!node)
return 1;
@@ -4402,7 +4300,7 @@ lt_dlloader_remove (loader_name)
errors = place->dlloader_exit (place->dlloader_data);
}
- LT_DLFREE (place);
+ free (place);
done:
LT_DLMUTEX_UNLOCK ();
- 110-gary-rationalise-memory-management.patch,
Gary V. Vaughan <=
- (no subject), Bob Friesenhahn, 2004/03/31
- Re:, Gary V . Vaughan, 2004/03/31
- Re:, Bob Friesenhahn, 2004/03/31
- Re: Re:, Gary V . Vaughan, 2004/03/31
- Re: molehill ----> mountain, Bob Friesenhahn, 2004/03/31
- Re: molehill ----> mountain, Gary V . Vaughan, 2004/03/31
- Re: molehill ----> mountain, Bob Friesenhahn, 2004/03/31
Re: 110-gary-rationalise-memory-management.patch, Bob Friesenhahn, 2004/03/31