Skip to content

Commit

Permalink
Merge pull request CESNET#29 from qmm161/master
Browse files Browse the repository at this point in the history
server BUGFIX incorrectly reused variable, memory leak
  • Loading branch information
michalvasko authored Sep 29, 2016
2 parents eddc7fa + 2ef57de commit 1b260cc
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions server/op_editconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ op_editconfig(struct lyd_node *rpc, struct nc_session *ncs)
enum NP2_EDIT_ERROPT erropt = NP2_EDIT_ERROPT_STOP;
struct lyxml_elem *config_xml;
struct lyd_node *config = NULL, *next, *iter;
char *str, path[1024], *rel;
char *str, path[1024], *rel, *valbuf;
const char *cstr;
enum NP2_EDIT_OP *op = NULL, *op_new;
int op_index, op_size, path_index = 0, missing_keys = 0, lastkey = 0;
Expand Down Expand Up @@ -245,7 +245,7 @@ op_editconfig(struct lyd_node *rpc, struct nc_session *ncs)
/*
* data manipulation
*/

valbuf = NULL;
op_size = 16;
op = malloc(op_size * sizeof *op);
op[0] = NP2_EDIT_NONE;
Expand Down Expand Up @@ -336,7 +336,7 @@ op_editconfig(struct lyd_node *rpc, struct nc_session *ncs)

if (op[op_index] < NP2_EDIT_DELETE) {
/* set value for sysrepo, it will be used as soon as all the keys are processed */
op_set_srval(iter, NULL, 0, &value, &str);
op_set_srval(iter, NULL, 0, &value, &valbuf);
}

/* the creation must be finished later when we get know keys */
Expand All @@ -352,7 +352,7 @@ op_editconfig(struct lyd_node *rpc, struct nc_session *ncs)

if (op[op_index] < NP2_EDIT_DELETE && !lastkey) {
/* set value for sysrepo */
op_set_srval(iter, NULL, 0, &value, &str);
op_set_srval(iter, NULL, 0, &value, &valbuf);
}

/* apply change to sysrepo */
Expand All @@ -378,9 +378,9 @@ op_editconfig(struct lyd_node *rpc, struct nc_session *ncs)
/* do nothing */
break;
}
if (str) {
free(str);
str = NULL;
if (valbuf) {
free(valbuf);
valbuf = NULL;
}

resultcheck:
Expand Down Expand Up @@ -543,7 +543,7 @@ op_editconfig(struct lyd_node *rpc, struct nc_session *ncs)
}
e = NULL;
}
goto errorreply;
goto internalerror;
default:
goto internalerror;
}
Expand Down

0 comments on commit 1b260cc

Please sign in to comment.