Commit a28a6369 authored by David Zeuthen's avatar David Zeuthen

hook up expat to use our memory handling API

Disable by default because, unfortunately, expat seems to leak on
certain OOM paths. Sigh.
parent 57891e74
......@@ -136,6 +136,41 @@ p_malloc0 (size_t bytes)
return p;
}
/**
* p_realloc:
* @p: memory previously allocated
* @bytes: new size
*
* Reallocate memory; like realloc(3).
*
* Returns: memory location or #NULL on OOM. Free with p_free().
*
* Since: 0.7
*/
void *
p_realloc (void *memory, size_t bytes)
{
void *p;
g_debug ("realloc %p %d", memory, bytes);
if (memory == NULL)
return p_malloc (bytes);
if (bytes == 0) {
p_free (memory);
return memory;
}
if (_fail_nth != -1 && _total_allocs == _fail_nth) {
return NULL;
}
p = realloc (memory, bytes);
return p;
}
/**
* p_free:
* @memory: pointer to memory allocated with p_malloc() + friends
......@@ -235,6 +270,12 @@ p_malloc0 (size_t bytes)
return calloc (1, bytes);
}
void *
p_realloc (void *memory, size_t bytes)
{
return realloc (memory, bytes);
}
void
p_free (void *memory)
{
......
......@@ -37,6 +37,7 @@ POLKIT_BEGIN_DECLS
void *p_malloc (size_t bytes);
void *p_malloc0 (size_t bytes);
void *p_realloc (void *memory, size_t bytes);
void p_free (void *memory);
/**
......
......@@ -493,7 +493,15 @@ polkit_policy_file_new (const char *path, polkit_bool_t load_descriptions, PolKi
}
pd.path = path;
/* #ifdef POLKIT_BUILD_TESTS
TODO: expat appears to leak on certain OOM paths
*/
#if 0
XML_Memory_Handling_Suite memsuite = {p_malloc, p_realloc, p_free};
pd.parser = XML_ParserCreate_MM (NULL, &memsuite, NULL);
#else
pd.parser = XML_ParserCreate (NULL);
#endif
pd.stack_depth = 0;
if (pd.parser == NULL) {
polkit_error_set_error (error, POLKIT_ERROR_OUT_OF_MEMORY,
......@@ -541,7 +549,11 @@ polkit_policy_file_new (const char *path, polkit_bool_t load_descriptions, PolKi
xml_res = XML_Parse (pd.parser, buf, buflen, 1);
if (xml_res == 0) {
if (pd.is_oom) {
if (XML_GetErrorCode (pd.parser) == XML_ERROR_NO_MEMORY) {
polkit_error_set_error (error, POLKIT_ERROR_OUT_OF_MEMORY,
"Out of memory parsing %s",
path);
} else if (pd.is_oom) {
polkit_error_set_error (error, POLKIT_ERROR_OUT_OF_MEMORY,
"Out of memory parsing %s",
path);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment