mirror of https://gitee.com/openkylin/libvirt.git
* src/virsh.c: catching memory allocation error and existing, as
pointed by Jim Meyering Daniel
This commit is contained in:
parent
85c23ead9e
commit
c9a8f27380
|
@ -1,3 +1,8 @@
|
||||||
|
Thu Mar 30 12:15:46 EST 2006 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
|
* src/virsh.c: catching memory allocation error and existing, as
|
||||||
|
pointed by Jim Meyering
|
||||||
|
|
||||||
Wed Mar 29 16:36:24 CEST 2006 Daniel Veillard <veillard@redhat.com>
|
Wed Mar 29 16:36:24 CEST 2006 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
* doc/*: rebuilt
|
* doc/*: rebuilt
|
||||||
|
|
25
src/virsh.c
25
src/virsh.c
|
@ -311,6 +311,11 @@ cmdList(vshControl * ctl, vshCmd * cmd ATTRIBUTE_UNUSED)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
ids = malloc(sizeof(int) * maxid);
|
ids = malloc(sizeof(int) * maxid);
|
||||||
|
if (ids == NULL) {
|
||||||
|
fprintf(stderr, "Failed to allocate %d bytes\n",
|
||||||
|
(int) sizeof(int) * maxid);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
virConnectListDomains(ctl->conn, &ids[0], maxid);
|
virConnectListDomains(ctl->conn, &ids[0], maxid);
|
||||||
|
|
||||||
vshPrint(ctl, VSH_HEADER, "%3s %-20s %s\n", "Id", "Name", "State");
|
vshPrint(ctl, VSH_HEADER, "%3s %-20s %s\n", "Id", "Name", "State");
|
||||||
|
@ -1284,6 +1289,10 @@ vshCommandGetToken(vshControl * ctl, char *str, char **end, char **res)
|
||||||
return VSH_TK_END;
|
return VSH_TK_END;
|
||||||
|
|
||||||
*res = malloc(sz + 1);
|
*res = malloc(sz + 1);
|
||||||
|
if (*res == NULL) {
|
||||||
|
fprintf(stderr, "Failed to allocate %d bytes\n", sz + 1);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
memcpy(*res, tkstr, sz);
|
memcpy(*res, tkstr, sz);
|
||||||
*(*res + sz) = '\0';
|
*(*res + sz) = '\0';
|
||||||
|
|
||||||
|
@ -1379,6 +1388,11 @@ vshCommandParse(vshControl * ctl, char *cmdstr)
|
||||||
if (opt) {
|
if (opt) {
|
||||||
/* save option */
|
/* save option */
|
||||||
vshCmdOpt *arg = malloc(sizeof(vshCmdOpt));
|
vshCmdOpt *arg = malloc(sizeof(vshCmdOpt));
|
||||||
|
if (arg == NULL) {
|
||||||
|
fprintf(stderr, "Failed to allocate %d bytes\n",
|
||||||
|
(int) sizeof(vshCmdOpt));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
arg->def = opt;
|
arg->def = opt;
|
||||||
arg->data = tkdata;
|
arg->data = tkdata;
|
||||||
|
@ -1405,6 +1419,12 @@ vshCommandParse(vshControl * ctl, char *cmdstr)
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
vshCmd *c = malloc(sizeof(vshCmd));
|
vshCmd *c = malloc(sizeof(vshCmd));
|
||||||
|
|
||||||
|
if (c == NULL) {
|
||||||
|
fprintf(stderr, "Failed to allocate %d bytes\n",
|
||||||
|
(int) sizeof(vshCmd));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
c->opts = first;
|
c->opts = first;
|
||||||
c->def = cmd;
|
c->def = cmd;
|
||||||
c->next = NULL;
|
c->next = NULL;
|
||||||
|
@ -1646,6 +1666,11 @@ vshReadlineOptionsGenerator(const char *text, int state)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
res = malloc(strlen(name) + 3);
|
res = malloc(strlen(name) + 3);
|
||||||
|
if (res == NULL) {
|
||||||
|
fprintf(stderr, "Failed to allocate %d bytes\n",
|
||||||
|
(int) strlen(name) + 3);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
sprintf(res, "--%s", name);
|
sprintf(res, "--%s", name);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue