+2004-09-01 Gary V. Vaughan <gary@gnu.org>
+
+ * libltdl/lt_dlloader.c (lt_dlloader_add): Handle malloc failure
+ from slist_new.
+ * libltdl/ltdl.c (loader_init): Trust lt_dlloader_add(), don't
+ overwrite its error type, and simplify.
+ Reported by Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
+
2004-09-01 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
* libltdl/slist.c (slist_new): Handle malloc failure gracefully.
int
lt_dlloader_add (const lt_dlvtable *vtable)
{
- if ((vtable == 0) /* diagnose null parameters */
+ SList *list;
+
+ if ((vtable == 0) /* diagnose invalid vtable fields */
|| (vtable->module_open == 0)
|| (vtable->module_close == 0)
- || (vtable->find_sym == 0))
+ || (vtable->find_sym == 0)
+ || ((vtable->priority != LT_DLLOADER_PREPEND) &&
+ (vtable->priority != LT_DLLOADER_APPEND)))
{
LT__SETERROR (INVALID_LOADER);
return RETURN_FAILURE;
}
- switch (vtable->priority)
+ list = slist_new (vtable);
+ if (!list)
{
- case LT_DLLOADER_PREPEND:
- loaders = slist_cons (slist_new (vtable), loaders);
- break;
-
- case LT_DLLOADER_APPEND:
- loaders = slist_concat (loaders, slist_new (vtable));
- break;
+ (*lt__alloc_die) ();
- default:
- LT__SETERROR (INVALID_LOADER);
+ /* Let the caller know something went wrong if lt__alloc_die
+ doesn't abort. */
return RETURN_FAILURE;
- /*NOTREACHED*/
+ }
+
+ if (vtable->priority == LT_DLLOADER_PREPEND)
+ {
+ loaders = slist_cons (list, loaders);
+ }
+ else
+ {
+ assert (vtable->priority == LT_DLLOADER_APPEND);
+ loaders = slist_concat (loaders, list);
}
return RETURN_SUCCESS;
vtable = (*vtable_func) (data);
}
- if (!vtable)
- {
- LT__SETERROR (INVALID_LOADER);
- ++errors;
- }
+ /* lt_dlloader_add will LT__SETERROR if it fails. */
+ errors += lt_dlloader_add (vtable);
- if (!errors)
- {
- if (lt_dlloader_add (vtable))
- {
- LT__SETERROR (DLOPEN_NOT_SUPPORTED);
- ++errors;
- }
- }
+ assert (errors || vtable);
if ((!errors) && vtable->dlloader_init)
{