Skip to content

Commit

Permalink
Merge pull request #1 from brianmichel/bmichel/fix-potential-leak
Browse files Browse the repository at this point in the history
Fix potential leak
  • Loading branch information
irace committed Jan 12, 2015
2 parents ae277e1 + 716343d commit 729f351
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions HTMLNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ void setAttributeNamed(xmlNode * node, const char * nameStr, const char * value)
char * newVal = (char *)malloc(strlen(value)+1);
memcpy (newVal, value, strlen(value)+1);

bool copyUsed = false;

for(xmlAttrPtr attr = node->properties; NULL != attr; attr = attr->next)
{
if (strcmp((char*)attr->name, nameStr) == 0)
Expand All @@ -37,12 +39,21 @@ void setAttributeNamed(xmlNode * node, const char * nameStr, const char * value)
{
free(child->content);
child->content = (xmlChar*)newVal;

if (!copyUsed)
{
copyUsed = true;
}
break;
}
break;
}
}

if (!copyUsed)
{
free(newVal);
}

}

Expand Down

0 comments on commit 729f351

Please sign in to comment.