From: Thadeu Lima de Souza Cascardo Date: Mon, 9 Feb 2009 02:01:44 +0000 (-0200) Subject: Set alternative content to NULL after free. X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fatompub.git;a=commitdiff_plain;h=0a6813d9bde8c34cd4f2b27ac1bc46eab2d1a281 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. --- 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); }