summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-04-02 13:27:22 +0200
committerChristian Grothoff <christian@grothoff.org>2021-04-02 13:27:22 +0200
commit25fd6dc25ada684cb52fb680d25d7810d85893fa (patch)
treee20e0f8c348873b2b0379019f350fa20d0c2edb9
parent4345e6b43447fd56213190b31e3ced2af1829f2d (diff)
downloadexchange-25fd6dc25ada684cb52fb680d25d7810d85893fa.tar.gz
exchange-25fd6dc25ada684cb52fb680d25d7810d85893fa.tar.bz2
exchange-25fd6dc25ada684cb52fb680d25d7810d85893fa.zip
fix misc leaks
-rw-r--r--src/json/json.c62
1 files changed, 38 insertions, 24 deletions
diff --git a/src/json/json.c b/src/json/json.c
index 2adf7118..fd526a1d 100644
--- a/src/json/json.c
+++ b/src/json/json.c
@@ -449,32 +449,34 @@ parse_path (json_t *obj,
char *next_path;
char *bracket;
json_t *next_obj = NULL;
+ char *next_dot;
- 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
+ if (NULL == next_id)
{
cb (cb_cls,
id,
prev);
+ GNUNET_free (id);
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 ((NULL == prev) &&
- (0 != strcmp (id,
- "$")))
+ if ( (NULL == prev) &&
+ (0 != strcmp (id,
+ "$")))
+ {
+ GNUNET_free (id);
+ GNUNET_free (next_path);
return GNUNET_SYSERR;
+ }
/* Check for bracketed indices */
if (NULL != bracket)
@@ -482,7 +484,11 @@ parse_path (json_t *obj,
char *end_bracket = strchr (bracket,
']');
if (NULL == end_bracket)
+ {
+ GNUNET_free (id);
+ GNUNET_free (next_path);
return GNUNET_SYSERR;
+ }
*end_bracket = '\0';
*bracket = '\0';
@@ -496,6 +502,7 @@ parse_path (json_t *obj,
size_t index;
json_t *value;
int ret = GNUNET_OK;
+
json_array_foreach (array, index, value) {
ret = parse_path (value,
obj,
@@ -505,6 +512,7 @@ parse_path (json_t *obj,
if (GNUNET_OK != ret)
{
GNUNET_free (id);
+ GNUNET_free (next_path);
return ret;
}
}
@@ -512,10 +520,15 @@ parse_path (json_t *obj,
else
{
unsigned int index;
+
if (1 != sscanf (bracket,
"%u",
&index))
+ {
+ GNUNET_free (id);
+ GNUNET_free (next_path);
return GNUNET_SYSERR;
+ }
next_obj = json_array_get (array,
index);
}
@@ -529,16 +542,17 @@ parse_path (json_t *obj,
if (NULL != next_obj)
{
- return parse_path (next_obj,
- obj,
- next_path,
- cb,
- cb_cls);
+ int ret = parse_path (next_obj,
+ obj,
+ next_path,
+ cb,
+ cb_cls);
+ GNUNET_free (id);
+ GNUNET_free (next_path);
+ return ret;
}
-
GNUNET_free (id);
GNUNET_free (next_path);
-
return GNUNET_OK;
}