Skip to content

Commit

Permalink
Avoid calling ckalloc on a length 0 buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Garrett McGrath committed Jul 11, 2019
1 parent 72de4fb commit f173602
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions generic/zookeepertcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1598,15 +1598,19 @@ zootcl_children_subcommand(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[],
}

int count = strings ? strings->count : 0;
Tcl_Obj **listObjv = (Tcl_Obj **)ckalloc (sizeof(Tcl_Obj *) * count);
if (count > 0) {
Tcl_Obj **listObjv = (Tcl_Obj **)ckalloc (sizeof(Tcl_Obj *) * count);

for (i = 0; i < count; i++) {
listObjv[i] = Tcl_NewStringObj (strings->data[i], -1);
}
for (i = 0; i < count; i++) {
listObjv[i] = Tcl_NewStringObj (strings->data[i], -1);
}

Tcl_Obj *listObj = Tcl_NewListObj (count, listObjv);
Tcl_SetObjResult (interp, listObj);
} else {
Tcl_SetObjResult (interp, Tcl_NewListObj (count, NULL));
}

Tcl_Obj *listObj = Tcl_NewListObj (count, listObjv);

Tcl_SetObjResult (interp, listObj);
ckfree (strings);
} else {
zootcl_callbackContext *ztc = (zootcl_callbackContext *)ckalloc (sizeof (zootcl_callbackContext));
Expand Down

0 comments on commit f173602

Please sign in to comment.