Add checks for failure of an allocation function from libxml (#8070)
g_malloc always trap on allocation errors but not xmlMalloc.
This commit is contained in:
parent
9854cd50f3
commit
9e5c4389a8
|
@ -71,6 +71,38 @@ fail_logger(const gchar *log_domain, GLogLevelFlags log_level,
|
|||
" «%d»", message, log_domain, log_level);
|
||||
}
|
||||
|
||||
static xmlFreeFunc free_func;
|
||||
static xmlMallocFunc malloc_func;
|
||||
static xmlReallocFunc realloc_func;
|
||||
static xmlStrdupFunc strdup_func;
|
||||
|
||||
void *
|
||||
my_malloc(size_t size)
|
||||
{
|
||||
void *ptr = malloc_func(size);
|
||||
if (! ptr) {
|
||||
fail("xmlMalloc failed");
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *
|
||||
my_realloc(void *mem, size_t size)
|
||||
{
|
||||
void *ptr = realloc_func(mem, size);
|
||||
if (! ptr) {
|
||||
fail("xmlRealloc failed");
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void
|
||||
setup_xml_mem_allocation()
|
||||
{
|
||||
xmlMemGet(&free_func, &malloc_func, &realloc_func, &strdup_func);
|
||||
xmlMemSetup(free_func, my_malloc, my_realloc, strdup_func);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -79,6 +111,7 @@ main(int argc, char *argv[])
|
|||
int i;
|
||||
int dont_fork = 0;
|
||||
|
||||
setup_xml_mem_allocation();
|
||||
for (i=1; i<argc; i++) {
|
||||
if (strcmp(argv[i], "--dontfork") == 0) {
|
||||
dont_fork = 1;
|
||||
|
|
Loading…
Reference in New Issue