Skip to content

Commit 8ea51e1

Browse files
authored
Merge pull request #5493 from YosysHQ/emil/sdc-fix-leak
sdc: use Tcl memory management functionality
2 parents 25ba41f + 6eb9e82 commit 8ea51e1

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

passes/cmds/sdc/sdc.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -349,20 +349,20 @@ static int getter_graph_node(TclCall call) {
349349
// to distinguish resolved and unknown getters.
350350
// For example, if call is ["get_foo", "-bar"]
351351
// then newCall is ["get_foo", "-getter-validated", "-bar"]
352-
Tcl_Obj* validity_tag = Tcl_NewStringObj("-getter-validated", -1);
353-
Tcl_IncrRefCount(validity_tag);
352+
Tcl_Obj* validity_tag = Tcl_NewStringObj("-getter-validated", -1);
353+
Tcl_IncrRefCount(validity_tag);
354354
std::vector<Tcl_Obj*> newObjv(call.objc + 1);
355-
log_assert(call.objc > 0);
355+
log_assert(call.objc > 0);
356356
newObjv[0] = call.objv[0];
357-
newObjv[1] = validity_tag;
358-
for (int i = 1; i < call.objc; ++i) {
359-
newObjv[i + 1] = call.objv[i];
360-
}
357+
newObjv[1] = validity_tag;
358+
for (int i = 1; i < call.objc; ++i) {
359+
newObjv[i + 1] = call.objv[i];
360+
}
361361
// Send the vector to the Tcl land
362-
Tcl_Obj** allocatedObjv = new Tcl_Obj*[call.objc + 1];
363-
for (int i = 0; i < call.objc + 1; ++i) {
364-
allocatedObjv[i] = newObjv[i];
365-
}
362+
Tcl_Obj** allocatedObjv = (Tcl_Obj**)Tcl_Alloc((call.objc + 1) * sizeof(Tcl_Obj*));
363+
for (int i = 0; i < call.objc + 1; ++i) {
364+
allocatedObjv[i] = newObjv[i];
365+
}
366366
TclCall newCall {
367367
.interp = call.interp,
368368
.objc = call.objc + 1,
@@ -376,14 +376,14 @@ static int redirect_unknown(TclCall call) {
376376
// TODO redirect to different command
377377
Tcl_Obj *newCmd = Tcl_NewStringObj("unknown", -1);
378378
auto newObjc = call.objc + 1;
379-
Tcl_Obj **newObjv = new Tcl_Obj*[newObjc];
379+
Tcl_Obj** newObjv = (Tcl_Obj**)Tcl_Alloc(newObjc * sizeof(Tcl_Obj*));
380380
newObjv[0] = newCmd;
381381
for (int i = 1; i < newObjc; i++) {
382382
newObjv[i] = call.objv[i - 1];
383383
}
384384
int result = Tcl_EvalObjv(call.interp, newObjc, newObjv, 0);
385385
Tcl_DecrRefCount(newCmd);
386-
delete[] newObjv;
386+
Tcl_Free((char*) newObjv);
387387
return result;
388388
}
389389

@@ -551,7 +551,7 @@ struct TclOpts {
551551
std::string expected = std::string("-") + opt_name;
552552
if (expected == arg) {
553553
if (!std::find_if(legals.begin(), legals.end(),
554-
[&opt_name](const char* str) { return opt_name == str; }))
554+
[&opt_name](const char* str) { return opt_name == str; }))
555555
log_cmd_error("Illegal argument %s for %s.\n", expected.c_str(), name);
556556
return true;
557557
}

0 commit comments

Comments
 (0)