slabtop: Reset slab_list if get_slabinfo() fails.

Otherwise "the state of 'list' and 'stats' are undefined" (as per
get_slabinfo()'s documentation) and free_slabinfo() crashes (a
use-after-free).
This commit is contained in:
Qualys Security Advisory 1970-01-01 00:00:00 +00:00 committed by Craig Small
parent 2fc42db322
commit 5f3c071cd3

View File

@ -364,6 +364,7 @@ int main(int argc, char *argv[])
memset(&stats, 0, sizeof(struct slab_stat)); memset(&stats, 0, sizeof(struct slab_stat));
if (get_slabinfo(&slab_list, &stats)) { if (get_slabinfo(&slab_list, &stats)) {
slab_list = NULL;
retval = EXIT_FAILURE; retval = EXIT_FAILURE;
break; break;
} }
@ -436,7 +437,8 @@ int main(int argc, char *argv[])
if (is_tty) if (is_tty)
tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_tty); tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_tty);
free_slabinfo(slab_list); if (slab_list)
free_slabinfo(slab_list);
if (!run_once) if (!run_once)
endwin(); endwin();
return retval; return retval;