Skip to content

Commit

Permalink
Fix leak when init_params() is called with valid filter
Browse files Browse the repository at this point in the history
  • Loading branch information
bbonev committed Jan 9, 2025
1 parent e70c745 commit 00a4e05
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
11 changes: 9 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,21 @@ You should have received a copy of the GNU General Public License along with thi
static const char *progname=NULL;
int maxpidlen=5;

config_t config;
params_t params;
config_t config={0};
params_t params={0};

view_init v_init_cb=view_curses_init;
view_fini v_fini_cb=view_curses_fini;
view_loop v_loop_cb=view_curses_loop;

inline void init_params(void) {
// initally params are zeroed; free the things possibly allocated on a second call
if (params.search_str)
free(params.search_str);
if (params.search_regx_ok)
regfree(&params.search_regx);
if (params.search_uc)
ucell_free(params.search_uc);
memset(&params,0,sizeof params);
params.iter=-1;
params.delay=1;
Expand Down
12 changes: 0 additions & 12 deletions src/view_curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -2059,18 +2059,6 @@ static inline int curses_key(int ch) {
case 'D':
init_params();
init_config();
// reset search regex
if (params.search_str)
free(params.search_str);
params.search_str=NULL;
if (params.search_regx_ok) {
regfree(&params.search_regx);
params.search_regx_ok=0;
}
if (params.search_uc) {
ucell_free(params.search_uc);
params.search_uc=NULL;
}
break;
case 'W':
config_file_save();
Expand Down

0 comments on commit 00a4e05

Please sign in to comment.