fix yet another error in "cmd" string handling in load_sym_def(). Added realloc of freed pointers detection in track_memory.awk

This commit is contained in:
stefan schippers 2023-05-05 09:29:30 +02:00
parent a185172b6b
commit b4b2c91481
3 changed files with 22 additions and 10 deletions

View File

@ -71,7 +71,6 @@ static void child_handler(int signum)
int main(int argc, char **argv)
{
int i;
my_strdup(_ALLOC_ID_, &xschem_executable, argv[0]);
signal(SIGINT, sig_handler);
signal(SIGSEGV, sig_handler);
signal(SIGILL, sig_handler);
@ -85,6 +84,7 @@ int main(int argc, char **argv)
if(!getenv("DISPLAY") || !getenv("DISPLAY")[0]) has_x=0;
#endif
argc = process_options(argc, argv);
my_strdup(_ALLOC_ID_, &xschem_executable, argv[0]);
if(debug_var>=1 && !has_x)
fprintf(errfp, "main(): no DISPLAY set, assuming no X available\n");
/* if detach is 1 no interactive command shell is created ...

View File

@ -3156,6 +3156,7 @@ int load_sym_def(const char *name, FILE *embed_fd)
xSymbol * symbol;
int symbols, sym_n_pins=0, generator;
char *cmd = NULL;
char *translated_cmd = NULL;
if(!name) {
dbg(0, "l_s_d(): Warning: name parameter set to NULL, returning with no action\n");
@ -3175,13 +3176,14 @@ int load_sym_def(const char *name, FILE *embed_fd)
dbg(1, "l_s_d(): cmd=%s\n", cmd);
generator = is_generator(cmd);
if(generator) {
cmd = get_generator_command(cmd);
translated_cmd = get_generator_command(cmd);
dbg(1, "l_s_d(): generator: cmd=%s\n", cmd);
if(cmd) {
lcc[level].fd = popen(cmd, "r"); /* execute ss="/path/to/xxx par1 par2 ..." and pipe in the stdout */
if(translated_cmd) {
lcc[level].fd = popen(translated_cmd, "r"); /* execute ss="/path/to/xxx par1 par2 ..." and pipe in the stdout */
} else {
lcc[level].fd = NULL;
}
my_free(_ALLOC_ID_, &translated_cmd);
} else if(!embed_fd) { /* regular symbol: open file */
if(!strcmp(xctx->file_version,"1.0")) {
my_strncpy(sympath, abs_sym_path(name, ".sym"), S(sympath));

View File

@ -52,6 +52,10 @@ BEGIN{
idx[$5] = id
}
else { # realloc
if(!($3 in address)) {
print "Corruption: address " $3 " was freed. Can not realloc. id=" id
print_source($3)
}
total += $7 - address[$3]
if(total > max) max = total
delete address[$3]
@ -73,14 +77,20 @@ END{
for(i in address) {
stale++
leak+= address[i]
print " address[ " i ", " idx[i] " ]= " address[i]
if(show_source) {
pipe = "egrep -n 'my_(malloc|calloc|realloc|free|mstrcat|strcat|strncat|strdup|strdup2)\\(" idx[i] ",' *.c xschem.h"
while( pipe | getline a) print " " a
close(pipe)
}
print_source(i)
}
print "Number of unfreed pointers = " stale
# as a crosscheck 'leak' should be equal to 'total'.
print "Total leaked memory = " leak
}
function print_source(add)
{
print " address[ " add ", " idx[add] " ]= " address[add]
if(show_source) {
pipe = "egrep -n 'my_(malloc|calloc|realloc|free|mstrcat|strcat|strncat|strdup|strdup2)\\(" idx[add] \
",' *.c xschem.h"
while( pipe | getline a) print " " a
close(pipe)
}
}