From 0a6813d9bde8c34cd4f2b27ac1bc46eab2d1a281 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Mon, 9 Feb 2009 00:01:44 -0200 Subject: [PATCH] Set alternative content to NULL after free. When setting the content using a type different from the original (src content instead of text content, for example), set the old content to NULL after releasing its memory. Otherwise, we try to free them when releasing the content object or setting the content again. --- atom/content.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/atom/content.c b/atom/content.c index 8dfbdd0..47fd693 100644 --- a/atom/content.c +++ b/atom/content.c @@ -139,9 +139,15 @@ atom_content_src_set (AtomContent *content, char *src) if (content->src) g_free (content->src); if (content->content) - g_free (content->content); + { + g_free (content->content); + content->content = NULL; + } if (content->xmlcontent) - xmlFreeNode (content->xmlcontent); + { + xmlFreeNode (content->xmlcontent); + content->xmlcontent = NULL; + } content->src = g_strdup (src); } @@ -173,9 +179,15 @@ atom_content_content_set (AtomContent *content, char *buffer, size_t len) if (content->content) g_free (content->content); if (content->src) - g_free (content->src); + { + g_free (content->src); + content->src = NULL; + } if (content->xmlcontent) - xmlFreeNode (content->xmlcontent); + { + xmlFreeNode (content->xmlcontent); + content->xmlcontent = NULL; + } content->content = g_malloc (len); memcpy (content->content, buffer, len); } @@ -246,8 +258,14 @@ atom_content_content_set_xmlnode (AtomContent *content, xmlNodePtr node) if (content->xmlcontent) xmlFreeNode (content->xmlcontent); if (content->content) - g_free (content->content); + { + g_free (content->content); + content->content = NULL; + } if (content->src) - g_free (content->src); + { + g_free (content->src); + content->src = NULL; + } content->xmlcontent = xmlCopyNodeList (node); } -- 2.20.1