From: Christian Stocker Date: Tue, 27 Aug 2002 06:54:21 +0000 (+0000) Subject: fix memleak in php_domxslt_string_to_xpathexpr X-Git-Tag: RELEASE_0_91~217 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e0b4533eeb4df9444174c026c53791f3187c2a9f;p=php fix memleak in php_domxslt_string_to_xpathexpr --- diff --git a/ext/domxml/php_domxml.c b/ext/domxml/php_domxml.c index 7b34a5f379..14e0d1d939 100644 --- a/ext/domxml/php_domxml.c +++ b/ext/domxml/php_domxml.c @@ -5051,20 +5051,21 @@ static char *php_domxslt_string_to_xpathexpr(const char *str TSRMLS_DC) const xmlChar *string = (const xmlChar *)str; xmlChar *value; - + int str_len; + + str_len = xmlStrlen(string) + 3; + if (xmlStrchr(string, '"')) { if (xmlStrchr(string, '\'')) { php_error(E_WARNING, "%s(): Cannot create XPath expression (string contains both quote and double-quotes)", get_active_function_name(TSRMLS_C)); return NULL; } - value = xmlStrdup((const xmlChar *)"'"); - value = xmlStrcat(value, string); - value = xmlStrcat(value, (const xmlChar *)"'"); + value = (xmlChar*) emalloc (str_len * sizeof(xmlChar *) ); + snprintf(value, str_len, "'%s'", string); } else { - value = xmlStrdup((const xmlChar *)"\""); - value = xmlStrcat(value, string); - value = xmlStrcat(value, (const xmlChar *)"\""); + value = (xmlChar*) emalloc (str_len * sizeof(xmlChar *) ); + snprintf(value, str_len, "\"%s\"", string); } return (char *)value;