aboutsummaryrefslogtreecommitdiff
path: root/src/tree.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2016-02-21 15:35:12 +0200
committerSergey Poznyakoff <gray@gnu.org>2016-02-21 15:35:12 +0200
commita3f25ce24dcaff123fb71db89419d3ae12ddb57a (patch)
tree4c0875505707d167b3529c75ce208c3d7eab23c4 /src/tree.c
parent08070e48d83cd34cddb08be33cf4993fc096c9c4 (diff)
downloadgrecs-a3f25ce24dcaff123fb71db89419d3ae12ddb57a.tar.gz
grecs-a3f25ce24dcaff123fb71db89419d3ae12ddb57a.tar.bz2
Prevent memory leaks when re-processing values of string type.
* src/grecs.hin (GRECS_CONST): New flag. * src/tree.c (grecs_string_convert): For string types, free the old value prior to assigning the new one, unless the GRECS_CONST flag is set. In any case, clear the GRECS_CONST flag after assigning new value.
Diffstat (limited to 'src/tree.c')
-rw-r--r--src/tree.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/tree.c b/src/tree.c
index 4f3189c..eea90a5 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -546,7 +546,7 @@ string_to_sockaddr(struct grecs_sockaddr *sp, const char *string,
int
grecs_string_convert(void *target, enum grecs_data_type type,
- const char *string, grecs_locus_t const *locus)
+ const char *string, grecs_locus_t const *locus)
{
switch (type) {
case grecs_type_void:
@@ -556,7 +556,7 @@ grecs_string_convert(void *target, enum grecs_data_type type,
break;
case grecs_type_string:
- *(const char**)target = grecs_strdup(string);
+ *(char**)target = grecs_strdup(string);
break;
case grecs_type_short:
@@ -824,10 +824,15 @@ grecs_process_ident(struct grecs_keyword *kwp, grecs_value_t *value,
grecs_list_append(list, ptr);
}
*(struct grecs_list**)target = list;
- } else
+ } else {
+ if (kwp->type == grecs_type_string
+ && !(kwp->flags & GRECS_CONST))
+ free(*(char**)target);
grecs_string_convert(target, kwp->type,
value->v.string,
&value->locus);
+ }
+ kwp->flags &= ~GRECS_CONST;
}

Return to:

Send suggestions and report system problems to the System administrator.