need to guard against null pointer dereference here.
* libltdl/ltdl.c (lt_dlcaller_register): Ditto.
2004-10-01 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
+ * libltdl/lt__alloc.c (lt__memdup): Allocation can fail, so we
+ need to guard against null pointer dereference here.
+ * libltdl/ltdl.c (lt_dlcaller_register): Ditto.
+
* libltdl/slist.c (slist_foreach): result was declared as
inner variable, shadowing the actually returned value.
void *
lt__memdup (void const *mem, size_t n)
{
- return memcpy (lt__malloc (n), mem, n);
+ void *newmem;
+
+ if ((newmem = lt__malloc (n)))
+ return memcpy (newmem, mem, n);
+
+ return 0;
}
char *
{
lt__caller_id *caller_id = lt__malloc (sizeof *caller_id);
- caller_id->id_string = lt__strdup (id_string);
- caller_id->iface = iface;
+ /* If lt__malloc fails, it will LT__SETERROR (NO_MEMORY), which
+ can then be detected with lt_dlerror() if we return 0. */
+ if (caller_id)
+ {
+ caller_id->id_string = lt__strdup (id_string);
+ caller_id->iface = iface;
+ }
return (lt_dlcaller_id) caller_id;
}