Skip to content

Commit

Permalink
Fix readline/editline memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
mmicko committed Oct 6, 2023
1 parent 8367f06 commit 2ab7d1d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions kernel/yosys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1353,8 +1353,12 @@ void shell(RTLIL::Design *design)
if ((command = fgets(command_buffer, 4096, stdin)) == NULL)
break;
#endif
if (command[strspn(command, " \t\r\n")] == 0)
if (command[strspn(command, " \t\r\n")] == 0) {
#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE)
free(command);
#endif
continue;
}
#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE)
add_history(command);
#endif
Expand All @@ -1376,10 +1380,17 @@ void shell(RTLIL::Design *design)
log_reset_stack();
}
design->check();
#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE)
if (command)
free(command);
#endif
}
if (command == NULL)
printf("exit\n");

#if defined(YOSYS_ENABLE_READLINE) || defined(YOSYS_ENABLE_EDITLINE)
else
free(command);
#endif
recursion_counter--;
log_cmd_error_throw = false;
}
Expand Down

0 comments on commit 2ab7d1d

Please sign in to comment.