summaryrefslogtreecommitdiff
path: root/cmd.c
diff options
context:
space:
mode:
authorPavel Borzenkov <pavel.borzenkov@gmail.com>2011-10-31 22:53:37 +0400
committerStefan Hajnoczi <stefanha@linux.vnet.ibm.com>2011-11-07 08:01:15 +0000
commitba7806ad92a2f6b1625cfa67d44dc1b71e3be44e (patch)
tree5973e7795e2898949933af1418f5a54b20d65730 /cmd.c
parent81beeec429f6bb8b0323e418a6aeef1a17b0cefa (diff)
downloadqemu-ba7806ad92a2f6b1625cfa67d44dc1b71e3be44e.tar.gz
qemu-ba7806ad92a2f6b1625cfa67d44dc1b71e3be44e.tar.bz2
qemu-ba7806ad92a2f6b1625cfa67d44dc1b71e3be44e.zip
cmd: Fix potential NULL pointer dereference
Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Diffstat (limited to 'cmd.c')
-rw-r--r--cmd.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/cmd.c b/cmd.c
index a6e3ef4b17..75415d86a2 100644
--- a/cmd.c
+++ b/cmd.c
@@ -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;
}