fix memory leak when using new resolved_net() fn

This commit is contained in:
stefan schippers 2023-05-27 14:13:50 +02:00
parent cf61c253c5
commit bb9ad82d80
3 changed files with 12 additions and 6 deletions

View File

@ -1878,7 +1878,8 @@ void select_hilight_net(void)
/* returns the full path name of "net" recursively resolving port connections
* propagating lower level nets to upper levels.
* "net" can be a bussed net. */
* "net" can be a bussed net.
* caller *MUST* free returned string */
char *resolved_net(const char *net)
{
char *rnet = NULL;

View File

@ -2933,7 +2933,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
* nets connected to I/O ports are mapped to upper level recursively */
else if(!strcmp(argv[1], "resolved_net"))
{
char *net = NULL;
char *net = NULL, *rn = NULL;
Tcl_ResetResult(interp);
prepare_netlist_structs(0);
if(xctx->lastsel == 1) {
@ -2952,7 +2952,9 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
}
}
}
Tcl_AppendResult(interp, resolved_net(net), NULL);
rn = resolved_net(net);
Tcl_AppendResult(interp, rn, NULL);
my_free(_ALLOC_ID_, &rn);
}
/* rotate

View File

@ -3290,10 +3290,13 @@ const char *translate(int inst, const char* s)
/* @#n:resolved_net attribute (n = pin number or name) will translate to hierarchy-resolved net */
if(!pin_attr_value && !strcmp(pin_attr, "resolved_net")) {
char *rn = NULL;
prepare_netlist_structs(0);
my_strdup2(_ALLOC_ID_, &pin_attr_value,
xctx->inst[inst].node && xctx->inst[inst].node[n] ?
resolved_net(xctx->inst[inst].node[n]) : "?");
if(xctx->inst[inst].node && xctx->inst[inst].node[n]) {
rn = resolved_net(xctx->inst[inst].node[n]);
}
my_strdup2(_ALLOC_ID_, &pin_attr_value, rn ? rn : "?");
if(rn) my_free(_ALLOC_ID_, &rn);
}
if(!pin_attr_value ) my_strdup(_ALLOC_ID_, &pin_attr_value, "--UNDEF--");