PolicyKit: Branch 'master'
David Zeuthen
david at kemper.freedesktop.org
Tue Nov 6 13:58:11 PST 2007
polkit/polkit-memory.c | 41 +++++++++++++++++++++++++++++++++++++++++
polkit/polkit-memory.h | 1 +
polkit/polkit-policy-file.c | 14 +++++++++++++-
3 files changed, 55 insertions(+), 1 deletion(-)
New commits:
commit a28a6369628d5affc32deb2516291f96fa463f70
Author: David Zeuthen <davidz at redhat.com>
Date: Tue Nov 6 16:55:08 2007 -0500
hook up expat to use our memory handling API
Disable by default because, unfortunately, expat seems to leak on
certain OOM paths. Sigh.
diff --git a/polkit/polkit-memory.c b/polkit/polkit-memory.c
index 0383e9b..c61edce 100644
--- a/polkit/polkit-memory.c
+++ b/polkit/polkit-memory.c
@@ -137,6 +137,41 @@ p_malloc0 (size_t bytes)
}
/**
+ * 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)
{
diff --git a/polkit/polkit-memory.h b/polkit/polkit-memory.h
index 607c2e5..78d3d83 100644
--- a/polkit/polkit-memory.h
+++ b/polkit/polkit-memory.h
@@ -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);
/**
diff --git a/polkit/polkit-policy-file.c b/polkit/polkit-policy-file.c
index 7d56f9d..d80ec22 100644
--- a/polkit/polkit-policy-file.c
+++ b/polkit/polkit-policy-file.c
@@ -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);
More information about the hal-commit
mailing list