fix misc leaks

This commit is contained in:
Christian Grothoff 2021-04-02 13:27:22 +02:00
parent 4345e6b434
commit 25fd6dc25a
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC

View File

@ -449,32 +449,34 @@ parse_path (json_t *obj,
char *next_path; char *next_path;
char *bracket; char *bracket;
json_t *next_obj = NULL; json_t *next_obj = NULL;
char *next_dot;
if (NULL != next_id) if (NULL == next_id)
{
bracket = strchr (next_id,
'[');
*next_id = '\0';
next_id++;
next_path = GNUNET_strdup (next_id);
char *next_dot = strchr (next_id,
'.');
if (NULL != next_dot)
*next_dot = '\0';
}
else
{ {
cb (cb_cls, cb (cb_cls,
id, id,
prev); prev);
GNUNET_free (id);
return GNUNET_OK; return GNUNET_OK;
} }
bracket = strchr (next_id,
'[');
*next_id = '\0';
next_id++;
next_path = GNUNET_strdup (next_id);
next_dot = strchr (next_id,
'.');
if (NULL != next_dot)
*next_dot = '\0';
/* If this is the first time this is called, make sure id is "$" */ /* If this is the first time this is called, make sure id is "$" */
if ((NULL == prev) && if ( (NULL == prev) &&
(0 != strcmp (id, (0 != strcmp (id,
"$"))) "$")))
{
GNUNET_free (id);
GNUNET_free (next_path);
return GNUNET_SYSERR; return GNUNET_SYSERR;
}
/* Check for bracketed indices */ /* Check for bracketed indices */
if (NULL != bracket) if (NULL != bracket)
@ -482,7 +484,11 @@ parse_path (json_t *obj,
char *end_bracket = strchr (bracket, char *end_bracket = strchr (bracket,
']'); ']');
if (NULL == end_bracket) if (NULL == end_bracket)
{
GNUNET_free (id);
GNUNET_free (next_path);
return GNUNET_SYSERR; return GNUNET_SYSERR;
}
*end_bracket = '\0'; *end_bracket = '\0';
*bracket = '\0'; *bracket = '\0';
@ -496,6 +502,7 @@ parse_path (json_t *obj,
size_t index; size_t index;
json_t *value; json_t *value;
int ret = GNUNET_OK; int ret = GNUNET_OK;
json_array_foreach (array, index, value) { json_array_foreach (array, index, value) {
ret = parse_path (value, ret = parse_path (value,
obj, obj,
@ -505,6 +512,7 @@ parse_path (json_t *obj,
if (GNUNET_OK != ret) if (GNUNET_OK != ret)
{ {
GNUNET_free (id); GNUNET_free (id);
GNUNET_free (next_path);
return ret; return ret;
} }
} }
@ -512,10 +520,15 @@ parse_path (json_t *obj,
else else
{ {
unsigned int index; unsigned int index;
if (1 != sscanf (bracket, if (1 != sscanf (bracket,
"%u", "%u",
&index)) &index))
{
GNUNET_free (id);
GNUNET_free (next_path);
return GNUNET_SYSERR; return GNUNET_SYSERR;
}
next_obj = json_array_get (array, next_obj = json_array_get (array,
index); index);
} }
@ -529,16 +542,17 @@ parse_path (json_t *obj,
if (NULL != next_obj) if (NULL != next_obj)
{ {
return parse_path (next_obj, int ret = parse_path (next_obj,
obj, obj,
next_path, next_path,
cb, cb,
cb_cls); cb_cls);
GNUNET_free (id);
GNUNET_free (next_path);
return ret;
} }
GNUNET_free (id); GNUNET_free (id);
GNUNET_free (next_path); GNUNET_free (next_path);
return GNUNET_OK; return GNUNET_OK;
} }