Fixed memory leak

This commit is contained in:
Jérôme Loyet 2011-07-05 01:43:50 +00:00
parent d12fab2d4b
commit e57914c1d8

View File

@ -123,6 +123,9 @@ static int fpm_conf_is_dir(char *path) /* {{{ */
} }
/* }}} */ /* }}} */
/*
* Expands the '$pool' token in a dynamically allocated string
*/
static int fpm_conf_expand_pool_name(char **value) { static int fpm_conf_expand_pool_name(char **value) {
char *token; char *token;
@ -130,15 +133,23 @@ static int fpm_conf_expand_pool_name(char **value) {
return 0; return 0;
} }
while ((token = strstr(*value, "$pool"))) { while (*value && (token = strstr(*value, "$pool"))) {
char *buf; char *buf;
char *p1 = *value;
char *p2 = token + strlen("$pool"); char *p2 = token + strlen("$pool");
/* If we are not in a pool, we cannot expand this name now */
if (!current_wp || !current_wp->config || !current_wp->config->name) { if (!current_wp || !current_wp->config || !current_wp->config->name) {
return -1; return -1;
} }
/* "aaa$poolbbb" becomes "aaa\0oolbbb" */
token[0] = '\0'; token[0] = '\0';
spprintf(&buf, 0, "%s%s%s", p1, current_wp->config->name, p2);
/* Build a brand new string with the expanded token */
spprintf(&buf, 0, "%s%s%s", *value, current_wp->config->name, p2);
/* Free the previous value and save the new one */
free(*value);
*value = strdup(buf); *value = strdup(buf);
efree(buf); efree(buf);
} }