提交 ba7806ad 编写于 作者: P Pavel Borzenkov 提交者: Stefan Hajnoczi

cmd: Fix potential NULL pointer dereference

Signed-off-by: NPavel Borzenkov <pavel.borzenkov@gmail.com>
Signed-off-by: NStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
上级 81beeec4
......@@ -47,7 +47,7 @@ compare(const void *a, const void *b)
void add_command(const cmdinfo_t *ci)
{
cmdtab = realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
cmdtab = g_realloc((void *)cmdtab, ++ncmds * sizeof(*cmdtab));
cmdtab[ncmds - 1] = *ci;
qsort(cmdtab, ncmds, sizeof(*cmdtab), compare);
}
......@@ -122,12 +122,7 @@ find_command(
void add_user_command(char *optarg)
{
ncmdline++;
cmdline = realloc(cmdline, ncmdline * sizeof(char *));
if (!cmdline) {
perror("realloc");
exit(1);
}
cmdline = g_realloc(cmdline, ++ncmdline * sizeof(char *));
cmdline[ncmdline-1] = optarg;
}
......@@ -190,7 +185,7 @@ void command_loop(void)
doneline(input, v);
}
if (cmdline) {
free(cmdline);
g_free(cmdline);
return;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册