mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-26 18:41:17 +00:00
Switch over remaining driver code to use memory alloc apis
This commit is contained in:
parent
d7d21c85e0
commit
d789ef5a88
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
|||||||
|
Fri Jun 6 12:01:00 BST 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
|
* src/bridge.c, src/conf.c, src/iptables.c, src/lxc_conf.c,
|
||||||
|
src/lxc_container.c, src/lxc_driver.c, src/openvz_conf.c,
|
||||||
|
src/openvz_driver.c, src/proxy_internal.c, src/remote_internal.c,
|
||||||
|
src/sexpr.c, src/storage_backend.c, src/storage_backend_disk.c,
|
||||||
|
src/storage_backend_fs.c, src/storage_backend_iscsi.c,
|
||||||
|
src/storage_backend_logical.c, src/storage_conf.c,
|
||||||
|
src/storage_driver.c, src/xen_internal.c, src/xen_unified.c,
|
||||||
|
src/xend_internal.c, src/xmlrpc.c: Switch over to use the
|
||||||
|
internal memory allocation APIs.
|
||||||
|
|
||||||
Fri Jun 6 11:41:00 BST 2008 Daniel P. Berrange <berrange@redhat.com>
|
Fri Jun 6 11:41:00 BST 2008 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
* qemud/event.c, qemud/mdns.c, qemud/qemud.c, qemud/remote.c:
|
* qemud/event.c, qemud/mdns.c, qemud/qemud.c, qemud/remote.c:
|
||||||
|
18
src/bridge.c
18
src/bridge.c
@ -45,6 +45,7 @@
|
|||||||
#include <net/if_arp.h> /* ARPHRD_ETHER */
|
#include <net/if_arp.h> /* ARPHRD_ETHER */
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
#define MAX_BRIDGE_ID 256
|
#define MAX_BRIDGE_ID 256
|
||||||
|
|
||||||
@ -84,8 +85,7 @@ brInit(brControl **ctlp)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
*ctlp = malloc(sizeof(**ctlp));
|
if (VIR_ALLOC(*ctlp) < 0) {
|
||||||
if (!*ctlp) {
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
@ -110,7 +110,7 @@ brShutdown(brControl *ctl)
|
|||||||
close(ctl->fd);
|
close(ctl->fd);
|
||||||
ctl->fd = 0;
|
ctl->fd = 0;
|
||||||
|
|
||||||
free(ctl);
|
VIR_FREE(ctl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -681,7 +681,7 @@ brSetForwardDelay(brControl *ctl ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
snprintf(delayStr, sizeof(delayStr), "%d", delay);
|
snprintf(delayStr, sizeof(delayStr), "%d", delay);
|
||||||
|
|
||||||
if (!(argv = calloc(n + 1, sizeof(*argv))))
|
if (VIR_ALLOC_N(argv, n + 1) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
@ -706,8 +706,8 @@ brSetForwardDelay(brControl *ctl ATTRIBUTE_UNUSED,
|
|||||||
if (argv) {
|
if (argv) {
|
||||||
n = 0;
|
n = 0;
|
||||||
while (argv[n])
|
while (argv[n])
|
||||||
free(argv[n++]);
|
VIR_FREE(argv[n++]);
|
||||||
free(argv);
|
VIR_FREE(argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
@ -738,7 +738,7 @@ brSetEnableSTP(brControl *ctl ATTRIBUTE_UNUSED,
|
|||||||
1 + /* brige name */
|
1 + /* brige name */
|
||||||
1; /* value */
|
1; /* value */
|
||||||
|
|
||||||
if (!(argv = calloc(n + 1, sizeof(*argv))))
|
if (VIR_ALLOC_N(argv, n + 1) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
@ -763,8 +763,8 @@ brSetEnableSTP(brControl *ctl ATTRIBUTE_UNUSED,
|
|||||||
if (argv) {
|
if (argv) {
|
||||||
n = 0;
|
n = 0;
|
||||||
while (argv[n])
|
while (argv[n])
|
||||||
free(argv[n++]);
|
VIR_FREE(argv[n++]);
|
||||||
free(argv);
|
VIR_FREE(argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
51
src/conf.c
51
src/conf.c
@ -23,6 +23,7 @@
|
|||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "c-ctype.h"
|
#include "c-ctype.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* *
|
* *
|
||||||
@ -138,11 +139,11 @@ __virConfFreeValue(virConfValuePtr val)
|
|||||||
return;
|
return;
|
||||||
if (val->type == VIR_CONF_STRING &&
|
if (val->type == VIR_CONF_STRING &&
|
||||||
val->str != NULL)
|
val->str != NULL)
|
||||||
free(val->str);
|
VIR_FREE(val->str);
|
||||||
if (val->type == VIR_CONF_LIST &&
|
if (val->type == VIR_CONF_LIST &&
|
||||||
val->list != NULL)
|
val->list != NULL)
|
||||||
virConfFreeList(val->list);
|
virConfFreeList(val->list);
|
||||||
free(val);
|
VIR_FREE(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
virConfPtr
|
virConfPtr
|
||||||
@ -150,8 +151,7 @@ __virConfNew(void)
|
|||||||
{
|
{
|
||||||
virConfPtr ret;
|
virConfPtr ret;
|
||||||
|
|
||||||
ret = calloc(1, sizeof(*ret));
|
if (VIR_ALLOC(ret) < 0) {
|
||||||
if (ret == NULL) {
|
|
||||||
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
|
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
@ -199,8 +199,7 @@ virConfAddEntry(virConfPtr conf, char *name, virConfValuePtr value, char *comm)
|
|||||||
if ((comm == NULL) && (name == NULL))
|
if ((comm == NULL) && (name == NULL))
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
|
||||||
ret = calloc(1, sizeof(*ret));
|
if (VIR_ALLOC(ret) < 0) {
|
||||||
if (ret == NULL) {
|
|
||||||
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
|
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
@ -441,7 +440,8 @@ virConfParseValue(virConfParserCtxtPtr ctxt)
|
|||||||
NEXT;
|
NEXT;
|
||||||
SKIP_BLANKS_AND_EOL;
|
SKIP_BLANKS_AND_EOL;
|
||||||
if ((ctxt->cur < ctxt->end) && (CUR != ']')) {
|
if ((ctxt->cur < ctxt->end) && (CUR != ']')) {
|
||||||
lst = virConfParseValue(ctxt);
|
if ((lst = virConfParseValue(ctxt)) == NULL)
|
||||||
|
return(NULL);
|
||||||
SKIP_BLANKS_AND_EOL;
|
SKIP_BLANKS_AND_EOL;
|
||||||
}
|
}
|
||||||
while ((ctxt->cur < ctxt->end) && (CUR != ']')) {
|
while ((ctxt->cur < ctxt->end) && (CUR != ']')) {
|
||||||
@ -484,10 +484,10 @@ virConfParseValue(virConfParserCtxtPtr ctxt)
|
|||||||
ctxt->line);
|
ctxt->line);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
ret = calloc(1, sizeof(*ret));
|
if (VIR_ALLOC(ret) < 0) {
|
||||||
if (ret == NULL) {
|
|
||||||
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
|
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
|
||||||
free(str);
|
virConfFreeList(lst);
|
||||||
|
VIR_FREE(str);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
ret->type = type;
|
ret->type = type;
|
||||||
@ -618,7 +618,7 @@ virConfParseStatement(virConfParserCtxtPtr ctxt)
|
|||||||
SKIP_BLANKS;
|
SKIP_BLANKS;
|
||||||
value = virConfParseValue(ctxt);
|
value = virConfParseValue(ctxt);
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
free(name);
|
VIR_FREE(name);
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
SKIP_BLANKS;
|
SKIP_BLANKS;
|
||||||
@ -630,15 +630,15 @@ virConfParseStatement(virConfParserCtxtPtr ctxt)
|
|||||||
if (comm == NULL) {
|
if (comm == NULL) {
|
||||||
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"),
|
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"),
|
||||||
ctxt->line);
|
ctxt->line);
|
||||||
free(name);
|
VIR_FREE(name);
|
||||||
virConfFreeValue(value);
|
virConfFreeValue(value);
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (virConfAddEntry(ctxt->conf, name, value, comm) == NULL) {
|
if (virConfAddEntry(ctxt->conf, name, value, comm) == NULL) {
|
||||||
free(name);
|
VIR_FREE(name);
|
||||||
virConfFreeValue(value);
|
virConfFreeValue(value);
|
||||||
free(comm);
|
VIR_FREE(comm);
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
return(0);
|
return(0);
|
||||||
@ -720,7 +720,7 @@ __virConfReadFile(const char *filename)
|
|||||||
|
|
||||||
conf = virConfParse(filename, content, len);
|
conf = virConfParse(filename, content, len);
|
||||||
|
|
||||||
free(content);
|
VIR_FREE(content);
|
||||||
|
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
@ -769,14 +769,14 @@ __virConfFree(virConfPtr conf)
|
|||||||
tmp = conf->entries;
|
tmp = conf->entries;
|
||||||
while (tmp) {
|
while (tmp) {
|
||||||
virConfEntryPtr next;
|
virConfEntryPtr next;
|
||||||
free(tmp->name);
|
VIR_FREE(tmp->name);
|
||||||
virConfFreeValue(tmp->value);
|
virConfFreeValue(tmp->value);
|
||||||
free(tmp->comment);
|
VIR_FREE(tmp->comment);
|
||||||
next = tmp->next;
|
next = tmp->next;
|
||||||
free(tmp);
|
VIR_FREE(tmp);
|
||||||
tmp = next;
|
tmp = next;
|
||||||
}
|
}
|
||||||
free(conf);
|
VIR_FREE(conf);
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -834,14 +834,14 @@ __virConfSetValue (virConfPtr conf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!cur) {
|
if (!cur) {
|
||||||
if (!(cur = malloc(sizeof(*cur)))) {
|
if (VIR_ALLOC(cur) < 0) {
|
||||||
virConfFreeValue(value);
|
virConfFreeValue(value);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
cur->comment = NULL;
|
cur->comment = NULL;
|
||||||
if (!(cur->name = strdup(setting))) {
|
if (!(cur->name = strdup(setting))) {
|
||||||
virConfFreeValue(value);
|
virConfFreeValue(value);
|
||||||
free(cur);
|
VIR_FREE(cur);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
cur->value = value;
|
cur->value = value;
|
||||||
@ -897,15 +897,16 @@ __virConfWriteFile(const char *filename, virConfPtr conf)
|
|||||||
|
|
||||||
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR );
|
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR );
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
char *tmp = virBufferContentAndReset(&buf);
|
||||||
virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to open file"), 0);
|
virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to open file"), 0);
|
||||||
free(virBufferContentAndReset(&buf));
|
VIR_FREE(tmp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
use = virBufferUse(&buf);
|
use = virBufferUse(&buf);
|
||||||
content = virBufferContentAndReset(&buf);
|
content = virBufferContentAndReset(&buf);
|
||||||
ret = safewrite(fd, content, use);
|
ret = safewrite(fd, content, use);
|
||||||
free(content);
|
VIR_FREE(content);
|
||||||
close(fd);
|
close(fd);
|
||||||
if (ret != (int)use) {
|
if (ret != (int)use) {
|
||||||
virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to save content"), 0);
|
virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to save content"), 0);
|
||||||
@ -955,11 +956,11 @@ __virConfWriteMem(char *memory, int *len, virConfPtr conf)
|
|||||||
|
|
||||||
if ((int)use >= *len) {
|
if ((int)use >= *len) {
|
||||||
*len = (int)use;
|
*len = (int)use;
|
||||||
free(content);
|
VIR_FREE(content);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(memory, content, use);
|
memcpy(memory, content, use);
|
||||||
free(content);
|
VIR_FREE(content);
|
||||||
*len = use;
|
*len = use;
|
||||||
return use;
|
return use;
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "iptables.h"
|
#include "iptables.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
#define qemudLog(level, msg...) fprintf(stderr, msg)
|
#define qemudLog(level, msg...) fprintf(stderr, msg)
|
||||||
|
|
||||||
@ -156,7 +157,7 @@ notifyRulesRemoved(const char *table,
|
|||||||
snprintf(arg, sizeof(arg), "--custom-rules=ipv4:%s:%s", table, path);
|
snprintf(arg, sizeof(arg), "--custom-rules=ipv4:%s:%s", table, path);
|
||||||
|
|
||||||
if (!stripLine(content, len, arg)) {
|
if (!stripLine(content, len, arg)) {
|
||||||
free(content);
|
VIR_FREE(content);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +172,7 @@ notifyRulesRemoved(const char *table,
|
|||||||
goto write_error;
|
goto write_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(content);
|
VIR_FREE(content);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -181,7 +182,7 @@ notifyRulesRemoved(const char *table,
|
|||||||
strerror(errno));
|
strerror(errno));
|
||||||
if (f)
|
if (f)
|
||||||
fclose(f);
|
fclose(f);
|
||||||
free(content);
|
VIR_FREE(content);
|
||||||
|
|
||||||
#undef MAX_FILE_LEN
|
#undef MAX_FILE_LEN
|
||||||
}
|
}
|
||||||
@ -264,14 +265,14 @@ iptRulesSave(iptRules *rules)
|
|||||||
static void
|
static void
|
||||||
iptRuleFree(iptRule *rule)
|
iptRuleFree(iptRule *rule)
|
||||||
{
|
{
|
||||||
free(rule->rule);
|
VIR_FREE(rule->rule);
|
||||||
rule->rule = NULL;
|
rule->rule = NULL;
|
||||||
|
|
||||||
if (rule->argv) {
|
if (rule->argv) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (rule->argv[i])
|
while (rule->argv[i])
|
||||||
free(rule->argv[i++]);
|
VIR_FREE(rule->argv[i++]);
|
||||||
free(rule->argv);
|
VIR_FREE(rule->argv);
|
||||||
rule->argv = NULL;
|
rule->argv = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -282,18 +283,14 @@ iptRulesAppend(iptRules *rules,
|
|||||||
char **argv,
|
char **argv,
|
||||||
int command_idx)
|
int command_idx)
|
||||||
{
|
{
|
||||||
iptRule *r;
|
if (VIR_REALLOC_N(rules->rules, rules->nrules+1) < 0) {
|
||||||
|
|
||||||
if (!(r = realloc(rules->rules, sizeof(*r) * (rules->nrules+1)))) {
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (argv[i])
|
while (argv[i])
|
||||||
free(argv[i++]);
|
VIR_FREE(argv[i++]);
|
||||||
free(argv);
|
VIR_FREE(argv);
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
rules->rules = r;
|
|
||||||
|
|
||||||
rules->rules[rules->nrules].rule = rule;
|
rules->rules[rules->nrules].rule = rule;
|
||||||
rules->rules[rules->nrules].argv = argv;
|
rules->rules[rules->nrules].argv = argv;
|
||||||
rules->rules[rules->nrules].command_idx = command_idx;
|
rules->rules[rules->nrules].command_idx = command_idx;
|
||||||
@ -332,23 +329,17 @@ iptRulesFree(iptRules *rules)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (rules->table) {
|
if (rules->table)
|
||||||
free(rules->table);
|
VIR_FREE(rules->table);
|
||||||
rules->table = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rules->chain) {
|
|
||||||
free(rules->chain);
|
|
||||||
rules->chain = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (rules->chain)
|
||||||
|
VIR_FREE(rules->chain);
|
||||||
|
|
||||||
if (rules->rules) {
|
if (rules->rules) {
|
||||||
for (i = 0; i < rules->nrules; i++)
|
for (i = 0; i < rules->nrules; i++)
|
||||||
iptRuleFree(&rules->rules[i]);
|
iptRuleFree(&rules->rules[i]);
|
||||||
|
|
||||||
free(rules->rules);
|
VIR_FREE(rules->rules);
|
||||||
rules->rules = NULL;
|
|
||||||
|
|
||||||
rules->nrules = 0;
|
rules->nrules = 0;
|
||||||
}
|
}
|
||||||
@ -358,7 +349,7 @@ iptRulesFree(iptRules *rules)
|
|||||||
rules->path[0] = '\0';
|
rules->path[0] = '\0';
|
||||||
#endif /* ENABLE_IPTABLES_LOKKIT */
|
#endif /* ENABLE_IPTABLES_LOKKIT */
|
||||||
|
|
||||||
free(rules);
|
VIR_FREE(rules);
|
||||||
}
|
}
|
||||||
|
|
||||||
static iptRules *
|
static iptRules *
|
||||||
@ -367,7 +358,7 @@ iptRulesNew(const char *table,
|
|||||||
{
|
{
|
||||||
iptRules *rules;
|
iptRules *rules;
|
||||||
|
|
||||||
if (!(rules = calloc(1, sizeof (*rules))))
|
if (VIR_ALLOC(rules) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(rules->table = strdup(table)))
|
if (!(rules->table = strdup(table)))
|
||||||
@ -404,8 +395,9 @@ argvToString(char **argv)
|
|||||||
for (len = 1, i = 0; argv[i]; i++)
|
for (len = 1, i = 0; argv[i]; i++)
|
||||||
len += strlen(argv[i]) + 1;
|
len += strlen(argv[i]) + 1;
|
||||||
|
|
||||||
if (!(p = ret = (char *)malloc(len)))
|
if (VIR_ALLOC_N(ret, len) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
p = ret;
|
||||||
|
|
||||||
for (i = 0; argv[i]; i++) {
|
for (i = 0; argv[i]; i++) {
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
@ -441,7 +433,7 @@ iptablesAddRemoveRule(iptRules *rules, int action, const char *arg, ...)
|
|||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
if (!(argv = calloc(n + 1, sizeof(*argv))))
|
if (VIR_ALLOC_N(argv, n + 1) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
@ -478,7 +470,7 @@ iptablesAddRemoveRule(iptRules *rules, int action, const char *arg, ...)
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (action == REMOVE) {
|
if (action == REMOVE) {
|
||||||
free(argv[command_idx]);
|
VIR_FREE(argv[command_idx]);
|
||||||
if (!(argv[command_idx] = strdup("--delete")))
|
if (!(argv[command_idx] = strdup("--delete")))
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -497,13 +489,13 @@ iptablesAddRemoveRule(iptRules *rules, int action, const char *arg, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
free(rule);
|
VIR_FREE(rule);
|
||||||
|
|
||||||
if (argv) {
|
if (argv) {
|
||||||
n = 0;
|
n = 0;
|
||||||
while (argv[n])
|
while (argv[n])
|
||||||
free(argv[n++]);
|
VIR_FREE(argv[n++]);
|
||||||
free(argv);
|
VIR_FREE(argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
@ -521,7 +513,7 @@ iptablesContextNew(void)
|
|||||||
{
|
{
|
||||||
iptablesContext *ctx;
|
iptablesContext *ctx;
|
||||||
|
|
||||||
if (!(ctx = calloc(1, sizeof (*ctx))))
|
if (VIR_ALLOC(ctx) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(ctx->input_filter = iptRulesNew("filter", "INPUT")))
|
if (!(ctx->input_filter = iptRulesNew("filter", "INPUT")))
|
||||||
@ -555,7 +547,7 @@ iptablesContextFree(iptablesContext *ctx)
|
|||||||
iptRulesFree(ctx->forward_filter);
|
iptRulesFree(ctx->forward_filter);
|
||||||
if (ctx->nat_postrouting)
|
if (ctx->nat_postrouting)
|
||||||
iptRulesFree(ctx->nat_postrouting);
|
iptRulesFree(ctx->nat_postrouting);
|
||||||
free(ctx);
|
VIR_FREE(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
#include "xml.h"
|
#include "xml.h"
|
||||||
|
#include "memory.h"
|
||||||
#include "lxc_conf.h"
|
#include "lxc_conf.h"
|
||||||
|
|
||||||
/* debug macros */
|
/* debug macros */
|
||||||
@ -183,10 +183,10 @@ static int lxcParseDomainUUID(virConnectPtr conn, unsigned char *uuid,
|
|||||||
if (virUUIDParse(res, uuid) < 0) {
|
if (virUUIDParse(res, uuid) < 0) {
|
||||||
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("invalid uuid element"));
|
_("invalid uuid element"));
|
||||||
free(res);
|
VIR_FREE(res);
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
free(res);
|
VIR_FREE(res);
|
||||||
}
|
}
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
@ -206,15 +206,14 @@ static int lxcParseDomainMounts(virConnectPtr conn,
|
|||||||
res = virXPathNodeSet("/domain/devices/filesystem", contextPtr, &list);
|
res = virXPathNodeSet("/domain/devices/filesystem", contextPtr, &list);
|
||||||
if (res > 0) {
|
if (res > 0) {
|
||||||
for (i = 0; i < res; ++i) {
|
for (i = 0; i < res; ++i) {
|
||||||
mountObj = calloc(1, sizeof(lxc_mount_t));
|
if (VIR_ALLOC(mountObj) < 0) {
|
||||||
if (NULL == mountObj) {
|
|
||||||
lxcError(conn, NULL, VIR_ERR_NO_MEMORY, "mount");
|
lxcError(conn, NULL, VIR_ERR_NO_MEMORY, "mount");
|
||||||
goto parse_complete;
|
goto parse_complete;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = lxcParseMountXML(conn, list[i], mountObj);
|
rc = lxcParseMountXML(conn, list[i], mountObj);
|
||||||
if (0 > rc) {
|
if (0 > rc) {
|
||||||
free(mountObj);
|
VIR_FREE(mountObj);
|
||||||
goto parse_complete;
|
goto parse_complete;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,7 +227,7 @@ static int lxcParseDomainMounts(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
prevObj = mountObj;
|
prevObj = mountObj;
|
||||||
}
|
}
|
||||||
free(list);
|
VIR_FREE(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = nmounts;
|
rc = nmounts;
|
||||||
@ -252,7 +251,7 @@ static int lxcParseDomainInit(virConnectPtr conn, char** init,
|
|||||||
if (strlen(res) >= PATH_MAX - 1) {
|
if (strlen(res) >= PATH_MAX - 1) {
|
||||||
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("init string too long"));
|
_("init string too long"));
|
||||||
free(res);
|
VIR_FREE(res);
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,7 +306,7 @@ static lxc_vm_def_t * lxcParseXML(virConnectPtr conn, xmlDocPtr docPtr)
|
|||||||
xmlChar *xmlProp = NULL;
|
xmlChar *xmlProp = NULL;
|
||||||
lxc_vm_def_t *containerDef;
|
lxc_vm_def_t *containerDef;
|
||||||
|
|
||||||
if (!(containerDef = calloc(1, sizeof(*containerDef)))) {
|
if (VIR_ALLOC(containerDef) < 0) {
|
||||||
lxcError(conn, NULL, VIR_ERR_NO_MEMORY, "containerDef");
|
lxcError(conn, NULL, VIR_ERR_NO_MEMORY, "containerDef");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -339,8 +338,7 @@ static lxc_vm_def_t * lxcParseXML(virConnectPtr conn, xmlDocPtr docPtr)
|
|||||||
_("invalid domain type"));
|
_("invalid domain type"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
free(xmlProp);
|
VIR_FREE(xmlProp);
|
||||||
xmlProp = NULL;
|
|
||||||
|
|
||||||
if ((xmlProp = xmlGetProp(rootNodePtr, BAD_CAST "id"))) {
|
if ((xmlProp = xmlGetProp(rootNodePtr, BAD_CAST "id"))) {
|
||||||
if (0 > virStrToLong_i((char*)xmlProp, NULL, 10, &(containerDef->id))) {
|
if (0 > virStrToLong_i((char*)xmlProp, NULL, 10, &(containerDef->id))) {
|
||||||
@ -357,8 +355,7 @@ static lxc_vm_def_t * lxcParseXML(virConnectPtr conn, xmlDocPtr docPtr)
|
|||||||
} else {
|
} else {
|
||||||
containerDef->id = -1;
|
containerDef->id = -1;
|
||||||
}
|
}
|
||||||
free(xmlProp);
|
VIR_FREE(xmlProp);
|
||||||
xmlProp = NULL;
|
|
||||||
|
|
||||||
if (lxcParseDomainName(conn, &(containerDef->name), contextPtr) < 0) {
|
if (lxcParseDomainName(conn, &(containerDef->name), contextPtr) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
@ -391,7 +388,7 @@ static lxc_vm_def_t * lxcParseXML(virConnectPtr conn, xmlDocPtr docPtr)
|
|||||||
return containerDef;
|
return containerDef;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
free(xmlProp);
|
VIR_FREE(xmlProp);
|
||||||
xmlXPathFreeContext(contextPtr);
|
xmlXPathFreeContext(contextPtr);
|
||||||
lxcFreeVMDef(containerDef);
|
lxcFreeVMDef(containerDef);
|
||||||
|
|
||||||
@ -442,7 +439,7 @@ lxc_vm_t * lxcAssignVMDef(virConnectPtr conn,
|
|||||||
return vm;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(vm = calloc(1, sizeof(lxc_vm_t)))) {
|
if (VIR_ALLOC(vm) < 0) {
|
||||||
lxcError(conn, NULL, VIR_ERR_NO_MEMORY, "vm");
|
lxcError(conn, NULL, VIR_ERR_NO_MEMORY, "vm");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -575,7 +572,7 @@ int lxcSaveConfig(virConnectPtr conn,
|
|||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(xmlDef);
|
VIR_FREE(xmlDef);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -689,7 +686,7 @@ int lxcLoadContainerConfigFile(lxc_driver_t *driver,
|
|||||||
|
|
||||||
lxcLoadConfig(driver, file, tempPath, xmlData);
|
lxcLoadConfig(driver, file, tempPath, xmlData);
|
||||||
|
|
||||||
free(xmlData);
|
VIR_FREE(xmlData);
|
||||||
|
|
||||||
load_complete:
|
load_complete:
|
||||||
return rc;
|
return rc;
|
||||||
@ -796,14 +793,14 @@ void lxcFreeVMDef(lxc_vm_def_t *vmdef)
|
|||||||
curMount = vmdef->mounts;
|
curMount = vmdef->mounts;
|
||||||
while (curMount) {
|
while (curMount) {
|
||||||
nextMount = curMount->next;
|
nextMount = curMount->next;
|
||||||
free(curMount);
|
VIR_FREE(curMount);
|
||||||
curMount = nextMount;
|
curMount = nextMount;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(vmdef->name);
|
VIR_FREE(vmdef->name);
|
||||||
free(vmdef->init);
|
VIR_FREE(vmdef->init);
|
||||||
free(vmdef->tty);
|
VIR_FREE(vmdef->tty);
|
||||||
free(vmdef);
|
VIR_FREE(vmdef);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lxcFreeVMs(lxc_vm_t *vms)
|
void lxcFreeVMs(lxc_vm_t *vms)
|
||||||
@ -821,8 +818,8 @@ void lxcFreeVMs(lxc_vm_t *vms)
|
|||||||
void lxcFreeVM(lxc_vm_t *vm)
|
void lxcFreeVM(lxc_vm_t *vm)
|
||||||
{
|
{
|
||||||
lxcFreeVMDef(vm->def);
|
lxcFreeVMDef(vm->def);
|
||||||
free(vm->containerTty);
|
VIR_FREE(vm->containerTty);
|
||||||
free(vm);
|
VIR_FREE(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
lxc_vm_t *lxcFindVMByID(const lxc_driver_t *driver, int id)
|
lxc_vm_t *lxcFindVMByID(const lxc_driver_t *driver, int id)
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include "lxc_container.h"
|
#include "lxc_container.h"
|
||||||
#include "lxc_conf.h"
|
#include "lxc_conf.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
|
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
|
||||||
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
|
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
|
||||||
@ -54,8 +55,8 @@ static int lxcExecContainerInit(const lxc_vm_def_t *vmDef)
|
|||||||
char* execString;
|
char* execString;
|
||||||
size_t execStringLen = strlen(vmDef->init) + 1 + 5;
|
size_t execStringLen = strlen(vmDef->init) + 1 + 5;
|
||||||
|
|
||||||
if (NULL == (execString = calloc(execStringLen, sizeof(char)))) {
|
if (VIR_ALLOC_N(execString, execStringLen) < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_NO_MEMORY,
|
lxcError(NULL, NULL, VIR_ERR_NO_MEMORY,
|
||||||
_("failed to calloc memory for init string: %s"),
|
_("failed to calloc memory for init string: %s"),
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto error_out;
|
goto error_out;
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#include "driver.h"
|
#include "driver.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
/* debug macros */
|
/* debug macros */
|
||||||
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
|
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
|
||||||
@ -85,8 +86,7 @@ static int lxcCheckContainerSupport( void )
|
|||||||
char *stack;
|
char *stack;
|
||||||
int childStatus;
|
int childStatus;
|
||||||
|
|
||||||
stack = malloc(getpagesize() * 4);
|
if (VIR_ALLOC_N(stack, getpagesize() * 4) < 0) {
|
||||||
if(!stack) {
|
|
||||||
DEBUG0("Unable to allocate stack");
|
DEBUG0("Unable to allocate stack");
|
||||||
rc = -1;
|
rc = -1;
|
||||||
goto check_complete;
|
goto check_complete;
|
||||||
@ -102,7 +102,7 @@ static int lxcCheckContainerSupport( void )
|
|||||||
waitpid(cpid, &childStatus, 0);
|
waitpid(cpid, &childStatus, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(stack);
|
VIR_FREE(stack);
|
||||||
|
|
||||||
check_complete:
|
check_complete:
|
||||||
return rc;
|
return rc;
|
||||||
@ -263,7 +263,7 @@ static int lxcListDefinedDomains(virConnectPtr conn,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
for (i = 0 ; i < numDoms ; i++) {
|
for (i = 0 ; i < numDoms ; i++) {
|
||||||
free(names[i]);
|
VIR_FREE(names[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@ -400,16 +400,15 @@ static int lxcStartContainer(virConnectPtr conn,
|
|||||||
int rc = -1;
|
int rc = -1;
|
||||||
int flags;
|
int flags;
|
||||||
int stacksize = getpagesize() * 4;
|
int stacksize = getpagesize() * 4;
|
||||||
void *stack, *stacktop;
|
char *stack, *stacktop;
|
||||||
|
|
||||||
/* allocate a stack for the container */
|
/* allocate a stack for the container */
|
||||||
stack = malloc(stacksize);
|
if (VIR_ALLOC_N(stack, stacksize) < 0) {
|
||||||
if (!stack) {
|
|
||||||
lxcError(conn, NULL, VIR_ERR_NO_MEMORY,
|
lxcError(conn, NULL, VIR_ERR_NO_MEMORY,
|
||||||
_("unable to allocate container stack"));
|
_("unable to allocate container stack"));
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
stacktop = (char*)stack + stacksize;
|
stacktop = stack + stacksize;
|
||||||
|
|
||||||
flags = CLONE_NEWPID|CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWUSER|CLONE_NEWIPC|SIGCHLD;
|
flags = CLONE_NEWPID|CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWUSER|CLONE_NEWIPC|SIGCHLD;
|
||||||
|
|
||||||
@ -574,8 +573,7 @@ static int lxcSetupContainerTty(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
*ttyName = malloc(sizeof(char) * (strlen(tempTtyName) + 1));
|
if (VIR_ALLOC_N(*ttyName, strlen(tempTtyName) + 1) < 0) {
|
||||||
if (NULL == ttyName) {
|
|
||||||
lxcError(conn, NULL, VIR_ERR_NO_MEMORY,
|
lxcError(conn, NULL, VIR_ERR_NO_MEMORY,
|
||||||
_("unable to allocate container name string"));
|
_("unable to allocate container name string"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1046,8 +1044,7 @@ static int lxcStartup(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
lxc_driver = calloc(1, sizeof(lxc_driver_t));
|
if (VIR_ALLOC(lxc_driver) < 0) {
|
||||||
if (NULL == lxc_driver) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1074,9 +1071,9 @@ static int lxcStartup(void)
|
|||||||
|
|
||||||
static void lxcFreeDriver(lxc_driver_t *driver)
|
static void lxcFreeDriver(lxc_driver_t *driver)
|
||||||
{
|
{
|
||||||
free(driver->configDir);
|
VIR_FREE(driver->configDir);
|
||||||
free(driver->stateDir);
|
VIR_FREE(driver->stateDir);
|
||||||
free(driver);
|
VIR_FREE(driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lxcShutdown(void)
|
static int lxcShutdown(void)
|
||||||
|
16
src/memory.c
16
src/memory.c
@ -77,22 +77,6 @@ static int virAllocTestFail(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Return 1 if an array of N objects, each of size S, cannot exist due
|
|
||||||
to size arithmetic overflow. S must be positive and N must be
|
|
||||||
nonnegative. This is a macro, not an inline function, so that it
|
|
||||||
works correctly even when SIZE_MAX < N.
|
|
||||||
|
|
||||||
By gnulib convention, SIZE_MAX represents overflow in size
|
|
||||||
calculations, so the conservative dividend to use here is
|
|
||||||
SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
|
|
||||||
However, malloc (SIZE_MAX) fails on all known hosts where
|
|
||||||
sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
|
|
||||||
exactly-SIZE_MAX allocations on such hosts; this avoids a test and
|
|
||||||
branch when S is known to be 1. */
|
|
||||||
# define xalloc_oversized(n, s) \
|
|
||||||
((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virAlloc:
|
* virAlloc:
|
||||||
* @ptrptr: pointer to pointer for address of allocated memory
|
* @ptrptr: pointer to pointer for address of allocated memory
|
||||||
|
19
src/memory.h
19
src/memory.h
@ -25,6 +25,25 @@
|
|||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
|
/* Return 1 if an array of N objects, each of size S, cannot exist due
|
||||||
|
to size arithmetic overflow. S must be positive and N must be
|
||||||
|
nonnegative. This is a macro, not an inline function, so that it
|
||||||
|
works correctly even when SIZE_MAX < N.
|
||||||
|
|
||||||
|
By gnulib convention, SIZE_MAX represents overflow in size
|
||||||
|
calculations, so the conservative dividend to use here is
|
||||||
|
SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
|
||||||
|
However, malloc (SIZE_MAX) fails on all known hosts where
|
||||||
|
sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
|
||||||
|
exactly-SIZE_MAX allocations on such hosts; this avoids a test and
|
||||||
|
branch when S is known to be 1. */
|
||||||
|
#ifndef xalloc_oversized
|
||||||
|
# define xalloc_oversized(n, s) \
|
||||||
|
((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Don't call these directly - use the macros below */
|
/* Don't call these directly - use the macros below */
|
||||||
int __virAlloc(void *ptrptr, size_t size) ATTRIBUTE_RETURN_CHECK;
|
int __virAlloc(void *ptrptr, size_t size) ATTRIBUTE_RETURN_CHECK;
|
||||||
int __virAllocN(void *ptrptr, size_t size, size_t count) ATTRIBUTE_RETURN_CHECK;
|
int __virAllocN(void *ptrptr, size_t size, size_t count) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
@ -53,6 +53,7 @@
|
|||||||
#include "openvz_conf.h"
|
#include "openvz_conf.h"
|
||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
#include "buf.h"
|
#include "buf.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -152,23 +153,22 @@ openvzFreeVMDef(struct openvz_vm_def *def)
|
|||||||
struct ovz_quota *prev = quota;
|
struct ovz_quota *prev = quota;
|
||||||
|
|
||||||
quota = quota->next;
|
quota = quota->next;
|
||||||
free(prev);
|
VIR_FREE(prev);
|
||||||
}
|
}
|
||||||
while (ip) {
|
while (ip) {
|
||||||
struct ovz_ip *prev = ip;
|
struct ovz_ip *prev = ip;
|
||||||
|
|
||||||
ip = ip->next;
|
ip = ip->next;
|
||||||
free(prev);
|
VIR_FREE(prev);
|
||||||
}
|
}
|
||||||
while (ns) {
|
while (ns) {
|
||||||
struct ovz_ns *prev = ns;
|
struct ovz_ns *prev = ns;
|
||||||
|
|
||||||
ns = ns->next;
|
ns = ns->next;
|
||||||
free(prev);
|
VIR_FREE(prev);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(def);
|
VIR_FREE(def);
|
||||||
def = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,8 +201,7 @@ openvzFreeVM(struct openvz_driver *driver, struct openvz_vm *vm,
|
|||||||
}
|
}
|
||||||
if (vms) {
|
if (vms) {
|
||||||
openvzFreeVMDef(vm->vmdef);
|
openvzFreeVMDef(vm->vmdef);
|
||||||
free(vm);
|
VIR_FREE(vm);
|
||||||
vm = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,8 +216,7 @@ openvzFreeDriver(struct openvz_driver *driver)
|
|||||||
if (driver->vms)
|
if (driver->vms)
|
||||||
for(next = driver->vms->next; driver->vms; driver->vms = next)
|
for(next = driver->vms->next; driver->vms; driver->vms = next)
|
||||||
openvzFreeVM(driver, driver->vms, 0);
|
openvzFreeVM(driver, driver->vms, 0);
|
||||||
free(driver);
|
VIR_FREE(driver);
|
||||||
driver = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct openvz_vm *
|
struct openvz_vm *
|
||||||
@ -247,7 +245,7 @@ openvzAssignVMDef(virConnectPtr conn,
|
|||||||
return vm;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(vm = calloc(1, sizeof(*vm)))) {
|
if (VIR_ALLOC(vm) < 0) {
|
||||||
openvzFreeVMDef(def);
|
openvzFreeVMDef(def);
|
||||||
error(conn, VIR_ERR_NO_MEMORY, "vm");
|
error(conn, VIR_ERR_NO_MEMORY, "vm");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -299,7 +297,7 @@ static struct openvz_vm_def
|
|||||||
struct ovz_ip *ovzIp;
|
struct ovz_ip *ovzIp;
|
||||||
struct ovz_ns *ovzNs;
|
struct ovz_ns *ovzNs;
|
||||||
|
|
||||||
if (!(def = calloc(1, sizeof(*def)))) {
|
if (VIR_ALLOC(def) < 0) {
|
||||||
error(conn, VIR_ERR_NO_MEMORY, "xmlXPathContext");
|
error(conn, VIR_ERR_NO_MEMORY, "xmlXPathContext");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -328,8 +326,7 @@ static struct openvz_vm_def
|
|||||||
error(conn, VIR_ERR_INTERNAL_ERROR, _("invalid domain type attribute"));
|
error(conn, VIR_ERR_INTERNAL_ERROR, _("invalid domain type attribute"));
|
||||||
goto bail_out;
|
goto bail_out;
|
||||||
}
|
}
|
||||||
free(prop);
|
VIR_FREE(prop);
|
||||||
prop = NULL;
|
|
||||||
|
|
||||||
/* Extract domain name */
|
/* Extract domain name */
|
||||||
obj = xmlXPathEval(BAD_CAST "string(/domain/name[1])", ctxt);
|
obj = xmlXPathEval(BAD_CAST "string(/domain/name[1])", ctxt);
|
||||||
@ -396,7 +393,7 @@ static struct openvz_vm_def
|
|||||||
error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage);
|
error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage);
|
||||||
goto bail_out;
|
goto bail_out;
|
||||||
}
|
}
|
||||||
if (!(ovzIp = calloc(1, sizeof(*ovzIp)))) {
|
if (VIR_ALLOC(ovzIp) < 0) {
|
||||||
openvzLog(OPENVZ_ERR,
|
openvzLog(OPENVZ_ERR,
|
||||||
_("Failed to Create Memory for 'ovz_ip' structure"));
|
_("Failed to Create Memory for 'ovz_ip' structure"));
|
||||||
goto bail_out;
|
goto bail_out;
|
||||||
@ -478,7 +475,7 @@ static struct openvz_vm_def
|
|||||||
error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage);
|
error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage);
|
||||||
goto bail_out;
|
goto bail_out;
|
||||||
}
|
}
|
||||||
if (!(ovzNs = calloc(1, sizeof(*ovzNs)))) {
|
if (VIR_ALLOC(ovzNs) < 0) {
|
||||||
openvzLog(OPENVZ_ERR,
|
openvzLog(OPENVZ_ERR,
|
||||||
_("Failed to Create Memory for 'ovz_ns' structure"));
|
_("Failed to Create Memory for 'ovz_ns' structure"));
|
||||||
goto bail_out;
|
goto bail_out;
|
||||||
@ -509,7 +506,7 @@ static struct openvz_vm_def
|
|||||||
return def;
|
return def;
|
||||||
|
|
||||||
bail_out:
|
bail_out:
|
||||||
free(prop);
|
VIR_FREE(prop);
|
||||||
xmlXPathFreeObject(obj);
|
xmlXPathFreeObject(obj);
|
||||||
xmlXPathFreeContext(ctxt);
|
xmlXPathFreeContext(ctxt);
|
||||||
openvzFreeVMDef(def);
|
openvzFreeVMDef(def);
|
||||||
@ -539,8 +536,7 @@ openvzGetVPSInfo(virConnectPtr conn) {
|
|||||||
}
|
}
|
||||||
pnext = &vm;
|
pnext = &vm;
|
||||||
while(!feof(fp)) {
|
while(!feof(fp)) {
|
||||||
*pnext = calloc(1, sizeof(**pnext));
|
if (VIR_ALLOC(*pnext) < 0) {
|
||||||
if(!*pnext) {
|
|
||||||
error(conn, VIR_ERR_INTERNAL_ERROR, _("calloc failed"));
|
error(conn, VIR_ERR_INTERNAL_ERROR, _("calloc failed"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -568,8 +564,7 @@ openvzGetVPSInfo(virConnectPtr conn) {
|
|||||||
(*pnext)->vpsid = -1;
|
(*pnext)->vpsid = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
vmdef = calloc(1, sizeof(*vmdef));
|
if (VIR_ALLOC(vmdef) < 0) {
|
||||||
if(!vmdef) {
|
|
||||||
error(conn, VIR_ERR_INTERNAL_ERROR, _("calloc failed"));
|
error(conn, VIR_ERR_INTERNAL_ERROR, _("calloc failed"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -581,7 +576,7 @@ openvzGetVPSInfo(virConnectPtr conn) {
|
|||||||
if(ret == -1) {
|
if(ret == -1) {
|
||||||
error(conn, VIR_ERR_INTERNAL_ERROR,
|
error(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("UUID in config file malformed"));
|
_("UUID in config file malformed"));
|
||||||
free(vmdef);
|
VIR_FREE(vmdef);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -594,8 +589,8 @@ error:
|
|||||||
struct openvz_vm *next;
|
struct openvz_vm *next;
|
||||||
|
|
||||||
next = vm->next;
|
next = vm->next;
|
||||||
free(vm->vmdef);
|
VIR_FREE(vm->vmdef);
|
||||||
free(vm);
|
VIR_FREE(vm);
|
||||||
vm = next;
|
vm = next;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -656,7 +651,7 @@ openvzGetVPSUUID(int vpsid, char *uuidstr)
|
|||||||
if (conf_dir == NULL)
|
if (conf_dir == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
sprintf(conf_file, "%s/%d.conf", conf_dir, vpsid);
|
sprintf(conf_file, "%s/%d.conf", conf_dir, vpsid);
|
||||||
free(conf_dir);
|
VIR_FREE(conf_dir);
|
||||||
|
|
||||||
fd = open(conf_file, O_RDWR);
|
fd = open(conf_file, O_RDWR);
|
||||||
if(fd == -1)
|
if(fd == -1)
|
||||||
@ -697,7 +692,7 @@ openvzSetUUID(int vpsid)
|
|||||||
if (conf_dir == NULL)
|
if (conf_dir == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
sprintf(conf_file, "%s/%d.conf", conf_dir, vpsid);
|
sprintf(conf_file, "%s/%d.conf", conf_dir, vpsid);
|
||||||
free(conf_dir);
|
VIR_FREE(conf_dir);
|
||||||
|
|
||||||
if (openvzGetVPSUUID(vpsid, uuidstr))
|
if (openvzGetVPSUUID(vpsid, uuidstr))
|
||||||
return -1;
|
return -1;
|
||||||
@ -741,7 +736,7 @@ int openvzAssignUUIDs(void)
|
|||||||
|
|
||||||
dp = opendir(conf_dir);
|
dp = opendir(conf_dir);
|
||||||
if(dp == NULL) {
|
if(dp == NULL) {
|
||||||
free(conf_dir);
|
VIR_FREE(conf_dir);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -753,7 +748,7 @@ int openvzAssignUUIDs(void)
|
|||||||
openvzSetUUID(vpsid);
|
openvzSetUUID(vpsid);
|
||||||
}
|
}
|
||||||
closedir(dp);
|
closedir(dp);
|
||||||
free(conf_dir);
|
VIR_FREE(conf_dir);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,8 +49,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
#include "libvirt/virterror.h"
|
#include "internal.h"
|
||||||
|
|
||||||
#include "openvz_driver.h"
|
#include "openvz_driver.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "buf.h"
|
#include "buf.h"
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "proxy_internal.h"
|
#include "proxy_internal.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "xen_unified.h"
|
#include "xen_unified.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
#define STANDALONE
|
#define STANDALONE
|
||||||
|
|
||||||
@ -992,8 +993,7 @@ xenProxyGetCapabilities (virConnectPtr conn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
xmllen = ans.len - sizeof (virProxyPacket);
|
xmllen = ans.len - sizeof (virProxyPacket);
|
||||||
xml = malloc (xmllen+1);
|
if (VIR_ALLOC_N(xml, xmllen+1) < 0) {
|
||||||
if (!xml) {
|
|
||||||
virProxyError (conn, VIR_ERR_NO_MEMORY, __FUNCTION__);
|
virProxyError (conn, VIR_ERR_NO_MEMORY, __FUNCTION__);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1044,7 +1044,7 @@ xenProxyDomainDumpXML(virDomainPtr domain, int flags ATTRIBUTE_UNUSED)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
xmllen = ans.len - sizeof(virProxyPacket);
|
xmllen = ans.len - sizeof(virProxyPacket);
|
||||||
if (!(xml = malloc(xmllen+1))) {
|
if (VIR_ALLOC_N(xml, xmllen+1) < 0) {
|
||||||
virProxyError(domain->conn, VIR_ERR_NO_MEMORY, __FUNCTION__);
|
virProxyError(domain->conn, VIR_ERR_NO_MEMORY, __FUNCTION__);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1097,7 +1097,7 @@ xenProxyDomainGetOSType(virDomainPtr domain)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
oslen = ans.len - sizeof(virProxyPacket);
|
oslen = ans.len - sizeof(virProxyPacket);
|
||||||
if (!(ostype = malloc(oslen+1))) {
|
if (VIR_ALLOC_N(ostype, oslen+1) < 0) {
|
||||||
virProxyError(domain->conn, VIR_ERR_NO_MEMORY, __FUNCTION__);
|
virProxyError(domain->conn, VIR_ERR_NO_MEMORY, __FUNCTION__);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,7 @@
|
|||||||
#include "qparams.h"
|
#include "qparams.h"
|
||||||
#include "remote_internal.h"
|
#include "remote_internal.h"
|
||||||
#include "remote_protocol.h"
|
#include "remote_protocol.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt,__VA_ARGS__)
|
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt,__VA_ARGS__)
|
||||||
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
|
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
|
||||||
@ -638,8 +639,7 @@ doRemoteOpen (virConnectPtr conn,
|
|||||||
|
|
||||||
// Generate the final command argv[] array.
|
// Generate the final command argv[] array.
|
||||||
// ssh -p $port [-l $username] $hostname $netcat -U $sockname [NULL]
|
// ssh -p $port [-l $username] $hostname $netcat -U $sockname [NULL]
|
||||||
cmd_argv = malloc (nr_args * sizeof (*cmd_argv));
|
if (VIR_ALLOC_N(cmd_argv, nr_args) < 0) {
|
||||||
if (cmd_argv == NULL) {
|
|
||||||
error (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
|
error (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
@ -702,8 +702,7 @@ doRemoteOpen (virConnectPtr conn,
|
|||||||
|
|
||||||
// Run the external process.
|
// Run the external process.
|
||||||
if (!cmd_argv) {
|
if (!cmd_argv) {
|
||||||
cmd_argv = malloc (2 * sizeof (*cmd_argv));
|
if (VIR_ALLOC_N(cmd_argv, 2) < 0) {
|
||||||
if (cmd_argv == NULL) {
|
|
||||||
error (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
|
error (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
@ -811,8 +810,7 @@ remoteOpen (virConnectPtr conn,
|
|||||||
if (inside_daemon)
|
if (inside_daemon)
|
||||||
return VIR_DRV_OPEN_DECLINED;
|
return VIR_DRV_OPEN_DECLINED;
|
||||||
|
|
||||||
priv = calloc (1, sizeof(*priv));
|
if (VIR_ALLOC(priv) < 0) {
|
||||||
if (!priv) {
|
|
||||||
error (conn, VIR_ERR_NO_MEMORY, _("struct private_data"));
|
error (conn, VIR_ERR_NO_MEMORY, _("struct private_data"));
|
||||||
return VIR_DRV_OPEN_ERROR;
|
return VIR_DRV_OPEN_ERROR;
|
||||||
}
|
}
|
||||||
@ -856,7 +854,7 @@ remoteOpen (virConnectPtr conn,
|
|||||||
ret = doRemoteOpen(conn, priv, uri, auth, rflags);
|
ret = doRemoteOpen(conn, priv, uri, auth, rflags);
|
||||||
if (ret != VIR_DRV_OPEN_SUCCESS) {
|
if (ret != VIR_DRV_OPEN_SUCCESS) {
|
||||||
conn->privateData = NULL;
|
conn->privateData = NULL;
|
||||||
free(priv);
|
VIR_FREE(priv);
|
||||||
} else {
|
} else {
|
||||||
priv->magic = MAGIC;
|
priv->magic = MAGIC;
|
||||||
conn->privateData = priv;
|
conn->privateData = priv;
|
||||||
@ -2268,9 +2266,7 @@ remoteDomainSetSchedulerParameters (virDomainPtr domain,
|
|||||||
|
|
||||||
/* Serialise the scheduler parameters. */
|
/* Serialise the scheduler parameters. */
|
||||||
args.params.params_len = nparams;
|
args.params.params_len = nparams;
|
||||||
args.params.params_val = malloc (sizeof (*args.params.params_val)
|
if (VIR_ALLOC_N(args.params.params_val, nparams) < 0) {
|
||||||
* nparams);
|
|
||||||
if (args.params.params_val == NULL) {
|
|
||||||
error (domain->conn, VIR_ERR_RPC, _("out of memory allocating array"));
|
error (domain->conn, VIR_ERR_RPC, _("out of memory allocating array"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -2446,9 +2442,9 @@ remoteNetworkOpen (virConnectPtr conn,
|
|||||||
* use the UNIX transport. This handles Xen driver
|
* use the UNIX transport. This handles Xen driver
|
||||||
* which doesn't have its own impl of the network APIs.
|
* which doesn't have its own impl of the network APIs.
|
||||||
*/
|
*/
|
||||||
struct private_data *priv = calloc (1, sizeof(*priv));
|
struct private_data *priv;
|
||||||
int ret, rflags = 0;
|
int ret, rflags = 0;
|
||||||
if (!priv) {
|
if (VIR_ALLOC(priv) < 0) {
|
||||||
error (conn, VIR_ERR_NO_MEMORY, _("struct private_data"));
|
error (conn, VIR_ERR_NO_MEMORY, _("struct private_data"));
|
||||||
return VIR_DRV_OPEN_ERROR;
|
return VIR_DRV_OPEN_ERROR;
|
||||||
}
|
}
|
||||||
@ -2461,7 +2457,7 @@ remoteNetworkOpen (virConnectPtr conn,
|
|||||||
ret = doRemoteOpen(conn, priv, uri, auth, rflags);
|
ret = doRemoteOpen(conn, priv, uri, auth, rflags);
|
||||||
if (ret != VIR_DRV_OPEN_SUCCESS) {
|
if (ret != VIR_DRV_OPEN_SUCCESS) {
|
||||||
conn->networkPrivateData = NULL;
|
conn->networkPrivateData = NULL;
|
||||||
free(priv);
|
VIR_FREE(priv);
|
||||||
} else {
|
} else {
|
||||||
priv->magic = MAGIC;
|
priv->magic = MAGIC;
|
||||||
priv->localUses = 1;
|
priv->localUses = 1;
|
||||||
@ -2480,7 +2476,7 @@ remoteNetworkClose (virConnectPtr conn)
|
|||||||
priv->localUses--;
|
priv->localUses--;
|
||||||
if (!priv->localUses) {
|
if (!priv->localUses) {
|
||||||
ret = doRemoteClose(conn, priv);
|
ret = doRemoteClose(conn, priv);
|
||||||
free(priv);
|
VIR_FREE(priv);
|
||||||
conn->networkPrivateData = NULL;
|
conn->networkPrivateData = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2852,9 +2848,9 @@ remoteStorageOpen (virConnectPtr conn,
|
|||||||
* use the UNIX transport. This handles Xen driver
|
* use the UNIX transport. This handles Xen driver
|
||||||
* which doesn't have its own impl of the network APIs.
|
* which doesn't have its own impl of the network APIs.
|
||||||
*/
|
*/
|
||||||
struct private_data *priv = calloc (1, sizeof(struct private_data));
|
struct private_data *priv;
|
||||||
int ret, rflags = 0;
|
int ret, rflags = 0;
|
||||||
if (!priv) {
|
if (VIR_ALLOC(priv) < 0) {
|
||||||
error (NULL, VIR_ERR_NO_MEMORY, _("struct private_data"));
|
error (NULL, VIR_ERR_NO_MEMORY, _("struct private_data"));
|
||||||
return VIR_DRV_OPEN_ERROR;
|
return VIR_DRV_OPEN_ERROR;
|
||||||
}
|
}
|
||||||
@ -2867,7 +2863,7 @@ remoteStorageOpen (virConnectPtr conn,
|
|||||||
ret = doRemoteOpen(conn, priv, uri, auth, rflags);
|
ret = doRemoteOpen(conn, priv, uri, auth, rflags);
|
||||||
if (ret != VIR_DRV_OPEN_SUCCESS) {
|
if (ret != VIR_DRV_OPEN_SUCCESS) {
|
||||||
conn->storagePrivateData = NULL;
|
conn->storagePrivateData = NULL;
|
||||||
free(priv);
|
VIR_FREE(priv);
|
||||||
} else {
|
} else {
|
||||||
priv->magic = MAGIC;
|
priv->magic = MAGIC;
|
||||||
priv->localUses = 1;
|
priv->localUses = 1;
|
||||||
@ -2886,7 +2882,7 @@ remoteStorageClose (virConnectPtr conn)
|
|||||||
priv->localUses--;
|
priv->localUses--;
|
||||||
if (!priv->localUses) {
|
if (!priv->localUses) {
|
||||||
ret = doRemoteClose(conn, priv);
|
ret = doRemoteClose(conn, priv);
|
||||||
free(priv);
|
VIR_FREE(priv);
|
||||||
conn->storagePrivateData = NULL;
|
conn->storagePrivateData = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3605,7 +3601,7 @@ remoteAuthenticate (virConnectPtr conn, struct private_data *priv, int in_open,
|
|||||||
mech = authtype + 5;
|
mech = authtype + 5;
|
||||||
|
|
||||||
if (remoteAuthSASL(conn, priv, in_open, auth, mech) < 0) {
|
if (remoteAuthSASL(conn, priv, in_open, auth, mech) < 0) {
|
||||||
free(ret.types.types_val);
|
VIR_FREE(ret.types.types_val);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -3615,7 +3611,7 @@ remoteAuthenticate (virConnectPtr conn, struct private_data *priv, int in_open,
|
|||||||
#if HAVE_POLKIT
|
#if HAVE_POLKIT
|
||||||
case REMOTE_AUTH_POLKIT:
|
case REMOTE_AUTH_POLKIT:
|
||||||
if (remoteAuthPolkit(conn, priv, in_open, auth) < 0) {
|
if (remoteAuthPolkit(conn, priv, in_open, auth) < 0) {
|
||||||
free(ret.types.types_val);
|
VIR_FREE(ret.types.types_val);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -3631,11 +3627,11 @@ remoteAuthenticate (virConnectPtr conn, struct private_data *priv, int in_open,
|
|||||||
NULL, NULL, NULL, 0, 0,
|
NULL, NULL, NULL, 0, 0,
|
||||||
_("unsupported authentication type %d"),
|
_("unsupported authentication type %d"),
|
||||||
ret.types.types_val[0]);
|
ret.types.types_val[0]);
|
||||||
free(ret.types.types_val);
|
VIR_FREE(ret.types.types_val);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(ret.types.types_val);
|
VIR_FREE(ret.types.types_val);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -3664,8 +3660,7 @@ static char *addrToString(struct sockaddr_storage *sa, socklen_t salen)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr = malloc(strlen(host) + 1 + strlen(port) + 1);
|
if (VIR_ALLOC_N(addr, strlen(host) + 1 + strlen(port) + 1) < 0) {
|
||||||
if (!addr) {
|
|
||||||
__virRaiseError (NULL, NULL, NULL, VIR_FROM_REMOTE,
|
__virRaiseError (NULL, NULL, NULL, VIR_FROM_REMOTE,
|
||||||
VIR_ERR_NO_MEMORY, VIR_ERR_ERROR,
|
VIR_ERR_NO_MEMORY, VIR_ERR_ERROR,
|
||||||
NULL, NULL, NULL, 0, 0,
|
NULL, NULL, NULL, 0, 0,
|
||||||
@ -3758,9 +3753,9 @@ static int remoteAuthCredSASL2Vir(int vircred)
|
|||||||
*/
|
*/
|
||||||
static sasl_callback_t *remoteAuthMakeCallbacks(int *credtype, int ncredtype)
|
static sasl_callback_t *remoteAuthMakeCallbacks(int *credtype, int ncredtype)
|
||||||
{
|
{
|
||||||
sasl_callback_t *cbs = calloc(ncredtype+1, sizeof (*cbs));
|
sasl_callback_t *cbs;
|
||||||
int i, n;
|
int i, n;
|
||||||
if (!cbs) {
|
if (VIR_ALLOC_N(cbs, ncredtype+1) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3795,14 +3790,13 @@ static int remoteAuthMakeCredentials(sasl_interact_t *interact,
|
|||||||
for (ninteract = 0 ; interact[ninteract].id != 0 ; ninteract++)
|
for (ninteract = 0 ; interact[ninteract].id != 0 ; ninteract++)
|
||||||
; /* empty */
|
; /* empty */
|
||||||
|
|
||||||
*cred = calloc(ninteract, sizeof(*cred));
|
if (VIR_ALLOC_N(*cred, ninteract) < 0)
|
||||||
if (!*cred)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (ninteract = 0 ; interact[ninteract].id != 0 ; ninteract++) {
|
for (ninteract = 0 ; interact[ninteract].id != 0 ; ninteract++) {
|
||||||
(*cred)[ninteract].type = remoteAuthCredSASL2Vir(interact[ninteract].id);
|
(*cred)[ninteract].type = remoteAuthCredSASL2Vir(interact[ninteract].id);
|
||||||
if (!(*cred)[ninteract].type) {
|
if (!(*cred)[ninteract].type) {
|
||||||
free(*cred);
|
VIR_FREE(*cred);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (interact[ninteract].challenge)
|
if (interact[ninteract].challenge)
|
||||||
@ -3821,8 +3815,8 @@ static void remoteAuthFreeCredentials(virConnectCredentialPtr cred,
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0 ; i < ncred ; i++)
|
for (i = 0 ; i < ncred ; i++)
|
||||||
free(cred[i].result);
|
VIR_FREE(cred[i].result);
|
||||||
free(cred);
|
VIR_FREE(cred);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -3990,7 +3984,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
|
|||||||
NULL, NULL, NULL, 0, 0,
|
NULL, NULL, NULL, 0, 0,
|
||||||
_("SASL mechanism %s not supported by server"),
|
_("SASL mechanism %s not supported by server"),
|
||||||
wantmech);
|
wantmech);
|
||||||
free(iret.mechlist);
|
VIR_FREE(iret.mechlist);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
mechlist = wantmech;
|
mechlist = wantmech;
|
||||||
@ -4009,7 +4003,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
|
|||||||
VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
|
VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
|
||||||
_("Failed to start SASL negotiation: %d (%s)"),
|
_("Failed to start SASL negotiation: %d (%s)"),
|
||||||
err, sasl_errdetail(saslconn));
|
err, sasl_errdetail(saslconn));
|
||||||
free(iret.mechlist);
|
VIR_FREE(iret.mechlist);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4026,7 +4020,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
|
|||||||
VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR,
|
VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR,
|
||||||
NULL, NULL, NULL, 0, 0,
|
NULL, NULL, NULL, 0, 0,
|
||||||
"%s", _("Failed to make auth credentials"));
|
"%s", _("Failed to make auth credentials"));
|
||||||
free(iret.mechlist);
|
VIR_FREE(iret.mechlist);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
/* Run the authentication callback */
|
/* Run the authentication callback */
|
||||||
@ -4044,7 +4038,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
|
|||||||
0, 0, "%s", msg);
|
0, 0, "%s", msg);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
free(iret.mechlist);
|
VIR_FREE(iret.mechlist);
|
||||||
|
|
||||||
if (clientoutlen > REMOTE_AUTH_SASL_DATA_MAX) {
|
if (clientoutlen > REMOTE_AUTH_SASL_DATA_MAX) {
|
||||||
__virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
|
__virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
|
||||||
@ -4123,8 +4117,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (serverin) {
|
if (serverin) {
|
||||||
free(serverin);
|
VIR_FREE(serverin);
|
||||||
serverin = NULL;
|
|
||||||
}
|
}
|
||||||
DEBUG("Client step result %d. Data %d bytes %p", err, clientoutlen, clientout);
|
DEBUG("Client step result %d. Data %d bytes %p", err, clientoutlen, clientout);
|
||||||
|
|
||||||
@ -4156,7 +4149,7 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
|
|||||||
|
|
||||||
/* This server call shows complete, and earlier client step was OK */
|
/* This server call shows complete, and earlier client step was OK */
|
||||||
if (complete && err == SASL_OK) {
|
if (complete && err == SASL_OK) {
|
||||||
free(serverin);
|
VIR_FREE(serverin);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4186,11 +4179,11 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
free(localAddr);
|
VIR_FREE(localAddr);
|
||||||
free(remoteAddr);
|
VIR_FREE(remoteAddr);
|
||||||
free(serverin);
|
VIR_FREE(serverin);
|
||||||
|
|
||||||
free(saslcb);
|
VIR_FREE(saslcb);
|
||||||
remoteAuthFreeCredentials(cred, ncred);
|
remoteAuthFreeCredentials(cred, ncred);
|
||||||
if (ret != 0 && saslconn)
|
if (ret != 0 && saslconn)
|
||||||
sasl_dispose(&saslconn);
|
sasl_dispose(&saslconn);
|
||||||
|
31
src/sexpr.c
31
src/sexpr.c
@ -21,6 +21,7 @@
|
|||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "sexpr.h"
|
#include "sexpr.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virSexprError:
|
* virSexprError:
|
||||||
@ -55,8 +56,7 @@ sexpr_new(void)
|
|||||||
{
|
{
|
||||||
struct sexpr *ret;
|
struct sexpr *ret;
|
||||||
|
|
||||||
ret = (struct sexpr *) malloc(sizeof(*ret));
|
if (VIR_ALLOC(ret) < 0) {
|
||||||
if (ret == NULL) {
|
|
||||||
virSexprError(VIR_ERR_NO_MEMORY, _("failed to allocate a node"));
|
virSexprError(VIR_ERR_NO_MEMORY, _("failed to allocate a node"));
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@ -85,13 +85,13 @@ sexpr_free(struct sexpr *sexpr)
|
|||||||
sexpr_free(sexpr->u.s.cdr);
|
sexpr_free(sexpr->u.s.cdr);
|
||||||
break;
|
break;
|
||||||
case SEXPR_VALUE:
|
case SEXPR_VALUE:
|
||||||
free(sexpr->u.value);
|
VIR_FREE(sexpr->u.value);
|
||||||
break;
|
break;
|
||||||
case SEXPR_NIL:
|
case SEXPR_NIL:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(sexpr);
|
VIR_FREE(sexpr);
|
||||||
|
|
||||||
errno = serrno;
|
errno = serrno;
|
||||||
}
|
}
|
||||||
@ -171,16 +171,23 @@ sexpr_cons(const struct sexpr *car, const struct sexpr *cdr)
|
|||||||
*
|
*
|
||||||
* Internal operation appending a value at the end of an existing list
|
* Internal operation appending a value at the end of an existing list
|
||||||
*/
|
*/
|
||||||
static void
|
static int
|
||||||
append(struct sexpr *lst, const struct sexpr *value)
|
append(struct sexpr *lst, const struct sexpr *value)
|
||||||
{
|
{
|
||||||
|
struct sexpr *nil = sexpr_nil();
|
||||||
|
|
||||||
|
if (nil == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
while (lst->kind != SEXPR_NIL) {
|
while (lst->kind != SEXPR_NIL) {
|
||||||
lst = lst->u.s.cdr;
|
lst = lst->u.s.cdr;
|
||||||
}
|
}
|
||||||
|
|
||||||
lst->kind = SEXPR_CONS;
|
lst->kind = SEXPR_CONS;
|
||||||
lst->u.s.car = (struct sexpr *) value;
|
lst->u.s.car = (struct sexpr *) value;
|
||||||
lst->u.s.cdr = sexpr_nil();
|
lst->u.s.cdr = nil;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,7 +205,8 @@ sexpr_append(struct sexpr *lst, const struct sexpr *value)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
return (lst);
|
return (lst);
|
||||||
append(lst, value);
|
if (append(lst, value) < 0)
|
||||||
|
return (NULL);
|
||||||
return (lst);
|
return (lst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,8 +326,11 @@ _string2sexpr(const char *buffer, size_t * end)
|
|||||||
|
|
||||||
tmp = _string2sexpr(ptr, &tmp_len);
|
tmp = _string2sexpr(ptr, &tmp_len);
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
return NULL;
|
goto error;
|
||||||
append(ret, tmp);
|
if (append(ret, tmp) < 0) {
|
||||||
|
sexpr_free(tmp);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
#if 0
|
#if 0
|
||||||
if (0) {
|
if (0) {
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
@ -351,6 +362,7 @@ _string2sexpr(const char *buffer, size_t * end)
|
|||||||
if (ret->u.value == NULL) {
|
if (ret->u.value == NULL) {
|
||||||
virSexprError(VIR_ERR_NO_MEMORY,
|
virSexprError(VIR_ERR_NO_MEMORY,
|
||||||
_("failed to copy a string"));
|
_("failed to copy a string"));
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*ptr == '\'')
|
if (*ptr == '\'')
|
||||||
@ -367,6 +379,7 @@ _string2sexpr(const char *buffer, size_t * end)
|
|||||||
if (ret->u.value == NULL) {
|
if (ret->u.value == NULL) {
|
||||||
virSexprError(VIR_ERR_NO_MEMORY,
|
virSexprError(VIR_ERR_NO_MEMORY,
|
||||||
_("failed to copy a string"));
|
_("failed to copy a string"));
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
#include "storage_backend.h"
|
#include "storage_backend.h"
|
||||||
#include "storage_backend_fs.h"
|
#include "storage_backend_fs.h"
|
||||||
@ -237,8 +238,7 @@ virStorageBackendUpdateVolInfoFD(virConnectPtr conn,
|
|||||||
vol->target.perms.uid = sb.st_uid;
|
vol->target.perms.uid = sb.st_uid;
|
||||||
vol->target.perms.gid = sb.st_gid;
|
vol->target.perms.gid = sb.st_gid;
|
||||||
|
|
||||||
free(vol->target.perms.label);
|
VIR_FREE(vol->target.perms.label);
|
||||||
vol->target.perms.label = NULL;
|
|
||||||
|
|
||||||
#if HAVE_SELINUX
|
#if HAVE_SELINUX
|
||||||
if (fgetfilecon(fd, &filecon) == -1) {
|
if (fgetfilecon(fd, &filecon) == -1) {
|
||||||
@ -310,9 +310,8 @@ virStorageBackendStablePath(virConnectPtr conn,
|
|||||||
if (dent->d_name[0] == '.')
|
if (dent->d_name[0] == '.')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
stablepath = malloc(strlen(pool->def->target.path) +
|
if (VIR_ALLOC_N(stablepath, strlen(pool->def->target.path) +
|
||||||
1 + strlen(dent->d_name) + 1);
|
1 + strlen(dent->d_name) + 1) < 0) {
|
||||||
if (stablepath == NULL) {
|
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("path"));
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("path"));
|
||||||
closedir(dh);
|
closedir(dh);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -327,7 +326,7 @@ virStorageBackendStablePath(virConnectPtr conn,
|
|||||||
return stablepath;
|
return stablepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(stablepath);
|
VIR_FREE(stablepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dh);
|
closedir(dh);
|
||||||
@ -365,7 +364,7 @@ virStorageBackendRunProgRegex(virConnectPtr conn,
|
|||||||
char **groups;
|
char **groups;
|
||||||
|
|
||||||
/* Compile all regular expressions */
|
/* Compile all regular expressions */
|
||||||
if ((reg = calloc(nregex, sizeof(*reg))) == NULL) {
|
if (VIR_ALLOC_N(reg, nregex) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("regex"));
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("regex"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -379,7 +378,7 @@ virStorageBackendRunProgRegex(virConnectPtr conn,
|
|||||||
_("Failed to compile regex %s"), error);
|
_("Failed to compile regex %s"), error);
|
||||||
for (j = 0 ; j <= i ; j++)
|
for (j = 0 ; j <= i ; j++)
|
||||||
regfree(®[j]);
|
regfree(®[j]);
|
||||||
free(reg);
|
VIR_FREE(reg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,12 +389,12 @@ virStorageBackendRunProgRegex(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Storage for matched variables */
|
/* Storage for matched variables */
|
||||||
if ((groups = calloc(totgroups, sizeof(*groups))) == NULL) {
|
if (VIR_ALLOC_N(groups, totgroups) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
||||||
"%s", _("regex groups"));
|
"%s", _("regex groups"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if ((vars = calloc(maxvars+1, sizeof(*vars))) == NULL) {
|
if (VIR_ALLOC_N(vars, maxvars+1) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
||||||
"%s", _("regex groups"));
|
"%s", _("regex groups"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -445,7 +444,7 @@ virStorageBackendRunProgRegex(virConnectPtr conn,
|
|||||||
|
|
||||||
/* Release matches & restart to matching the first regex */
|
/* Release matches & restart to matching the first regex */
|
||||||
for (j = 0 ; j < totgroups ; j++) {
|
for (j = 0 ; j < totgroups ; j++) {
|
||||||
free(groups[j]);
|
VIR_FREE(groups[j]);
|
||||||
groups[j] = NULL;
|
groups[j] = NULL;
|
||||||
}
|
}
|
||||||
maxReg = 0;
|
maxReg = 0;
|
||||||
@ -460,15 +459,15 @@ virStorageBackendRunProgRegex(virConnectPtr conn,
|
|||||||
cleanup:
|
cleanup:
|
||||||
if (groups) {
|
if (groups) {
|
||||||
for (j = 0 ; j < totgroups ; j++)
|
for (j = 0 ; j < totgroups ; j++)
|
||||||
free(groups[j]);
|
VIR_FREE(groups[j]);
|
||||||
free(groups);
|
VIR_FREE(groups);
|
||||||
}
|
}
|
||||||
free(vars);
|
VIR_FREE(vars);
|
||||||
|
|
||||||
for (i = 0 ; i < nregex ; i++)
|
for (i = 0 ; i < nregex ; i++)
|
||||||
regfree(®[i]);
|
regfree(®[i]);
|
||||||
|
|
||||||
free(reg);
|
VIR_FREE(reg);
|
||||||
|
|
||||||
if (list)
|
if (list)
|
||||||
fclose(list);
|
fclose(list);
|
||||||
@ -534,8 +533,7 @@ virStorageBackendRunProgNul(virConnectPtr conn,
|
|||||||
if (n_columns == 0)
|
if (n_columns == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (n_columns > SIZE_MAX / sizeof *v
|
if (VIR_ALLOC_N(v, n_columns) < 0) {
|
||||||
|| (v = malloc (n_columns * sizeof *v)) == NULL) {
|
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
||||||
"%s", _("n_columns too large"));
|
"%s", _("n_columns too large"));
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "storage_backend_disk.h"
|
#include "storage_backend_disk.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
VIR_STORAGE_POOL_DISK_DOS = 0,
|
VIR_STORAGE_POOL_DISK_DOS = 0,
|
||||||
@ -174,7 +175,7 @@ virStorageBackendDiskMakeDataVol(virConnectPtr conn,
|
|||||||
char *tmp, *devpath;
|
char *tmp, *devpath;
|
||||||
|
|
||||||
if (vol == NULL) {
|
if (vol == NULL) {
|
||||||
if ((vol = calloc(1, sizeof(virStorageVolDef))) == NULL) {
|
if (VIR_ALLOC(vol) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, _("volume"));
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, _("volume"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -211,8 +212,7 @@ virStorageBackendDiskMakeDataVol(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (devpath != vol->target.path)
|
if (devpath != vol->target.path)
|
||||||
free(devpath);
|
VIR_FREE(devpath);
|
||||||
devpath = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vol->key == NULL) {
|
if (vol->key == NULL) {
|
||||||
@ -224,8 +224,7 @@ virStorageBackendDiskMakeDataVol(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (vol->source.extents == NULL) {
|
if (vol->source.extents == NULL) {
|
||||||
if ((vol->source.extents =
|
if (VIR_ALLOC(vol->source.extents) < 0) {
|
||||||
calloc(1, sizeof(*(vol->source.extents)))) == NULL) {
|
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
||||||
_("volume extents"));
|
_("volume extents"));
|
||||||
return -1;
|
return -1;
|
||||||
@ -275,16 +274,15 @@ virStorageBackendDiskMakeFreeExtent(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
virStoragePoolObjPtr pool,
|
virStoragePoolObjPtr pool,
|
||||||
char **const groups)
|
char **const groups)
|
||||||
{
|
{
|
||||||
virStoragePoolSourceDeviceExtentPtr tmp;
|
|
||||||
virStoragePoolSourceDevicePtr dev = &pool->def->source.devices[0];
|
virStoragePoolSourceDevicePtr dev = &pool->def->source.devices[0];
|
||||||
|
|
||||||
if ((tmp = realloc(dev->freeExtents,
|
if (VIR_REALLOC_N(dev->freeExtents,
|
||||||
sizeof(*tmp) * (dev->nfreeExtent+1))) == NULL)
|
dev->nfreeExtent + 1) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
dev->freeExtents = tmp;
|
|
||||||
|
|
||||||
memset(dev->freeExtents +
|
memset(dev->freeExtents +
|
||||||
dev->nfreeExtent, 0, sizeof(*tmp));
|
dev->nfreeExtent, 0,
|
||||||
|
sizeof(dev->freeExtents[0]));
|
||||||
|
|
||||||
if (virStrToLong_ull(groups[3], NULL, 10,
|
if (virStrToLong_ull(groups[3], NULL, 10,
|
||||||
&dev->freeExtents[dev->nfreeExtent].start) < 0)
|
&dev->freeExtents[dev->nfreeExtent].start) < 0)
|
||||||
@ -388,9 +386,8 @@ static int
|
|||||||
virStorageBackendDiskRefreshPool(virConnectPtr conn,
|
virStorageBackendDiskRefreshPool(virConnectPtr conn,
|
||||||
virStoragePoolObjPtr pool)
|
virStoragePoolObjPtr pool)
|
||||||
{
|
{
|
||||||
free(pool->def->source.devices[0].freeExtents);
|
VIR_FREE(pool->def->source.devices[0].freeExtents);
|
||||||
pool->def->source.devices[0].nfreeExtent = 0;
|
pool->def->source.devices[0].nfreeExtent = 0;
|
||||||
pool->def->source.devices[0].freeExtents = NULL;
|
|
||||||
|
|
||||||
return virStorageBackendDiskReadPartitions(conn, pool, NULL);
|
return virStorageBackendDiskReadPartitions(conn, pool, NULL);
|
||||||
}
|
}
|
||||||
@ -476,9 +473,8 @@ virStorageBackendDiskCreateVol(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Blow away free extent info, as we're about to re-populate it */
|
/* Blow away free extent info, as we're about to re-populate it */
|
||||||
free(pool->def->source.devices[0].freeExtents);
|
VIR_FREE(pool->def->source.devices[0].freeExtents);
|
||||||
pool->def->source.devices[0].nfreeExtent = 0;
|
pool->def->source.devices[0].nfreeExtent = 0;
|
||||||
pool->def->source.devices[0].freeExtents = NULL;
|
|
||||||
|
|
||||||
/* Fetch actual extent info */
|
/* Fetch actual extent info */
|
||||||
if (virStorageBackendDiskReadPartitions(conn, pool, vol) < 0)
|
if (virStorageBackendDiskReadPartitions(conn, pool, vol) < 0)
|
||||||
|
@ -40,8 +40,7 @@
|
|||||||
#include "storage_backend_fs.h"
|
#include "storage_backend_fs.h"
|
||||||
#include "storage_conf.h"
|
#include "storage_conf.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "config.h"
|
#include "memory.h"
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
VIR_STORAGE_POOL_FS_AUTO = 0,
|
VIR_STORAGE_POOL_FS_AUTO = 0,
|
||||||
@ -530,25 +529,27 @@ virStorageBackendFileSystemMount(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
|
if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
|
||||||
src = malloc(strlen(pool->def->source.host.name) +
|
if (VIR_ALLOC_N(src, strlen(pool->def->source.host.name) +
|
||||||
1 + strlen(pool->def->source.dir) + 1);
|
1 + strlen(pool->def->source.dir) + 1) < 0) {
|
||||||
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("source"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
strcpy(src, pool->def->source.host.name);
|
strcpy(src, pool->def->source.host.name);
|
||||||
strcat(src, ":");
|
strcat(src, ":");
|
||||||
strcat(src, pool->def->source.dir);
|
strcat(src, pool->def->source.dir);
|
||||||
} else {
|
} else {
|
||||||
src = strdup(pool->def->source.devices[0].path);
|
if ((src = strdup(pool->def->source.devices[0].path)) == NULL) {
|
||||||
}
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("source"));
|
||||||
if (src == NULL) {
|
return -1;
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("source"));
|
}
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
mntargv[3] = src;
|
mntargv[3] = src;
|
||||||
|
|
||||||
if (virRun(conn, (char**)mntargv, NULL) < 0) {
|
if (virRun(conn, (char**)mntargv, NULL) < 0) {
|
||||||
free(src);
|
VIR_FREE(src);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
free(src);
|
VIR_FREE(src);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -679,8 +680,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn,
|
|||||||
virStorageVolDefPtr vol;
|
virStorageVolDefPtr vol;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
vol = calloc(1, sizeof(virStorageVolDef));
|
if (VIR_ALLOC(vol) < 0) {
|
||||||
if (vol == NULL) {
|
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
||||||
"%s", _("volume"));
|
"%s", _("volume"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -688,18 +688,17 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn,
|
|||||||
|
|
||||||
vol->name = strdup(ent->d_name);
|
vol->name = strdup(ent->d_name);
|
||||||
if (vol->name == NULL) {
|
if (vol->name == NULL) {
|
||||||
free(vol);
|
VIR_FREE(vol);
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
||||||
"%s", _("volume name"));
|
"%s", _("volume name"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
vol->target.format = VIR_STORAGE_VOL_RAW; /* Real value is filled in during probe */
|
vol->target.format = VIR_STORAGE_VOL_RAW; /* Real value is filled in during probe */
|
||||||
vol->target.path = malloc(strlen(pool->def->target.path) +
|
if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) +
|
||||||
1 + strlen(vol->name) + 1);
|
1 + strlen(vol->name) + 1) < 0) {
|
||||||
if (vol->target.path == NULL) {
|
VIR_FREE(vol->target.path);
|
||||||
free(vol->target.path);
|
VIR_FREE(vol);
|
||||||
free(vol);
|
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
||||||
"%s", _("volume name"));
|
"%s", _("volume name"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -708,19 +707,19 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn,
|
|||||||
strcat(vol->target.path, "/");
|
strcat(vol->target.path, "/");
|
||||||
strcat(vol->target.path, vol->name);
|
strcat(vol->target.path, vol->name);
|
||||||
if ((vol->key = strdup(vol->target.path)) == NULL) {
|
if ((vol->key = strdup(vol->target.path)) == NULL) {
|
||||||
free(vol->name);
|
VIR_FREE(vol->name);
|
||||||
free(vol->target.path);
|
VIR_FREE(vol->target.path);
|
||||||
free(vol);
|
VIR_FREE(vol);
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
||||||
"%s", _("volume key"));
|
"%s", _("volume key"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = virStorageBackendProbeFile(conn, vol) < 0)) {
|
if ((ret = virStorageBackendProbeFile(conn, vol) < 0)) {
|
||||||
free(vol->key);
|
VIR_FREE(vol->key);
|
||||||
free(vol->name);
|
VIR_FREE(vol->name);
|
||||||
free(vol->target.path);
|
VIR_FREE(vol->target.path);
|
||||||
free(vol);
|
VIR_FREE(vol);
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
else
|
else
|
||||||
@ -821,9 +820,8 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
|
|||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
vol->target.path = malloc(strlen(pool->def->target.path) +
|
if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) +
|
||||||
1 + strlen(vol->name) + 1);
|
1 + strlen(vol->name) + 1) < 0) {
|
||||||
if (vol->target.path == NULL) {
|
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("target"));
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("target"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "storage_backend_iscsi.h"
|
#include "storage_backend_iscsi.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStorageBackendISCSITargetIP(virConnectPtr conn,
|
virStorageBackendISCSITargetIP(virConnectPtr conn,
|
||||||
@ -253,7 +254,7 @@ virStorageBackendISCSIMakeLUN(virConnectPtr conn,
|
|||||||
|
|
||||||
snprintf(lunid, sizeof(lunid)-1, "lun-%s", groups[3]);
|
snprintf(lunid, sizeof(lunid)-1, "lun-%s", groups[3]);
|
||||||
|
|
||||||
if ((vol = calloc(1, sizeof(virStorageVolDef))) == NULL) {
|
if (VIR_ALLOC(vol) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -263,14 +264,13 @@ virStorageBackendISCSIMakeLUN(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((devpath = malloc(5 + strlen(dev) + 1)) == NULL) {
|
if (VIR_ALLOC_N(devpath, 5 + strlen(dev) + 1) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("devpath"));
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("devpath"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
strcpy(devpath, "/dev/");
|
strcpy(devpath, "/dev/");
|
||||||
strcat(devpath, dev);
|
strcat(devpath, dev);
|
||||||
free(dev);
|
VIR_FREE(dev);
|
||||||
dev = NULL;
|
|
||||||
/* It can take a little while between logging into the ISCSI
|
/* It can take a little while between logging into the ISCSI
|
||||||
* server and udev creating the /dev nodes, so if we get ENOENT
|
* server and udev creating the /dev nodes, so if we get ENOENT
|
||||||
* we must retry a few times - they should eventually appear.
|
* we must retry a few times - they should eventually appear.
|
||||||
@ -303,8 +303,7 @@ virStorageBackendISCSIMakeLUN(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (devpath != vol->target.path)
|
if (devpath != vol->target.path)
|
||||||
free(devpath);
|
VIR_FREE(devpath);
|
||||||
devpath = NULL;
|
|
||||||
|
|
||||||
if (virStorageBackendUpdateVolInfoFD(conn, vol, fd, 1) < 0)
|
if (virStorageBackendUpdateVolInfoFD(conn, vol, fd, 1) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -330,9 +329,9 @@ virStorageBackendISCSIMakeLUN(virConnectPtr conn,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (fd != -1) close(fd);
|
if (fd != -1) close(fd);
|
||||||
free(devpath);
|
VIR_FREE(devpath);
|
||||||
virStorageVolDefFree(vol);
|
virStorageVolDefFree(vol);
|
||||||
free(dev);
|
VIR_FREE(dev);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,8 +421,7 @@ virStorageBackendISCSIPortal(virConnectPtr conn,
|
|||||||
ipaddr, sizeof(ipaddr)) < 0)
|
ipaddr, sizeof(ipaddr)) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
portal = malloc(strlen(ipaddr) + 1 + 4 + 2 + 1);
|
if (VIR_ALLOC_N(portal, strlen(ipaddr) + 1 + 4 + 2 + 1) < 0) {
|
||||||
if (portal == NULL) {
|
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("portal"));
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("portal"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -457,10 +455,10 @@ virStorageBackendISCSIStartPool(virConnectPtr conn,
|
|||||||
if ((portal = virStorageBackendISCSIPortal(conn, pool)) == NULL)
|
if ((portal = virStorageBackendISCSIPortal(conn, pool)) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
if (virStorageBackendISCSILogin(conn, pool, portal) < 0) {
|
if (virStorageBackendISCSILogin(conn, pool, portal) < 0) {
|
||||||
free(portal);
|
VIR_FREE(portal);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
free(portal);
|
VIR_FREE(portal);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,12 +476,12 @@ virStorageBackendISCSIRefreshPool(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (virStorageBackendISCSIFindLUNs(conn, pool, session) < 0)
|
if (virStorageBackendISCSIFindLUNs(conn, pool, session) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
free(session);
|
VIR_FREE(session);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
free(session);
|
VIR_FREE(session);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -498,10 +496,10 @@ virStorageBackendISCSIStopPool(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virStorageBackendISCSILogout(conn, pool, portal) < 0) {
|
if (virStorageBackendISCSILogout(conn, pool, portal) < 0) {
|
||||||
free(portal);
|
VIR_FREE(portal);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
free(portal);
|
VIR_FREE(portal);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
#include "storage_backend_logical.h"
|
#include "storage_backend_logical.h"
|
||||||
#include "storage_conf.h"
|
#include "storage_conf.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
#define PV_BLANK_SECTOR_SIZE 512
|
#define PV_BLANK_SECTOR_SIZE 512
|
||||||
|
|
||||||
@ -97,7 +97,6 @@ virStorageBackendLogicalMakeVol(virConnectPtr conn,
|
|||||||
void *data)
|
void *data)
|
||||||
{
|
{
|
||||||
virStorageVolDefPtr vol = NULL;
|
virStorageVolDefPtr vol = NULL;
|
||||||
virStorageVolSourceExtentPtr tmp;
|
|
||||||
unsigned long long offset, size, length;
|
unsigned long long offset, size, length;
|
||||||
|
|
||||||
/* See if we're only looking for a specific volume */
|
/* See if we're only looking for a specific volume */
|
||||||
@ -113,7 +112,7 @@ virStorageBackendLogicalMakeVol(virConnectPtr conn,
|
|||||||
|
|
||||||
/* Or a completely new volume */
|
/* Or a completely new volume */
|
||||||
if (vol == NULL) {
|
if (vol == NULL) {
|
||||||
if ((vol = calloc(1, sizeof(*vol))) == NULL) {
|
if (VIR_ALLOC(vol) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -129,8 +128,8 @@ virStorageBackendLogicalMakeVol(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (vol->target.path == NULL) {
|
if (vol->target.path == NULL) {
|
||||||
if ((vol->target.path = malloc(strlen(pool->def->target.path) +
|
if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) +
|
||||||
1 + strlen(vol->name) + 1)) == NULL) {
|
1 + strlen(vol->name) + 1) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -150,12 +149,11 @@ virStorageBackendLogicalMakeVol(virConnectPtr conn,
|
|||||||
|
|
||||||
|
|
||||||
/* Finally fill in extents information */
|
/* Finally fill in extents information */
|
||||||
if ((tmp = realloc(vol->source.extents, sizeof(*tmp)
|
if (VIR_REALLOC_N(vol->source.extents,
|
||||||
* (vol->source.nextent + 1))) == NULL) {
|
vol->source.nextent + 1) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("extents"));
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("extents"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
vol->source.extents = tmp;
|
|
||||||
|
|
||||||
if ((vol->source.extents[vol->source.nextent].path =
|
if ((vol->source.extents[vol->source.nextent].path =
|
||||||
strdup(groups[2])) == NULL) {
|
strdup(groups[2])) == NULL) {
|
||||||
@ -266,7 +264,7 @@ virStorageBackendLogicalBuildPool(virConnectPtr conn,
|
|||||||
memset(zeros, 0, sizeof(zeros));
|
memset(zeros, 0, sizeof(zeros));
|
||||||
|
|
||||||
/* XXX multiple pvs */
|
/* XXX multiple pvs */
|
||||||
if ((vgargv = malloc(sizeof(char*) * (1))) == NULL) {
|
if (VIR_ALLOC_N(vgargv, 1) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("command line"));
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("command line"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -318,12 +316,12 @@ virStorageBackendLogicalBuildPool(virConnectPtr conn,
|
|||||||
if (virRun(conn, (char**)vgargv, NULL) < 0)
|
if (virRun(conn, (char**)vgargv, NULL) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
free(vgargv);
|
VIR_FREE(vgargv);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
free(vgargv);
|
VIR_FREE(vgargv);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
#include "buf.h"
|
#include "buf.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
#define virStorageLog(msg...) fprintf(stderr, msg)
|
#define virStorageLog(msg...) fprintf(stderr, msg)
|
||||||
|
|
||||||
@ -70,40 +71,40 @@ virStorageReportError(virConnectPtr conn, int code, const char *fmt, ...) {
|
|||||||
void
|
void
|
||||||
virStorageVolDefFree(virStorageVolDefPtr def) {
|
virStorageVolDefFree(virStorageVolDefPtr def) {
|
||||||
int i;
|
int i;
|
||||||
free(def->name);
|
VIR_FREE(def->name);
|
||||||
free(def->key);
|
VIR_FREE(def->key);
|
||||||
|
|
||||||
for (i = 0 ; i < def->source.nextent ; i++) {
|
for (i = 0 ; i < def->source.nextent ; i++) {
|
||||||
free(def->source.extents[i].path);
|
VIR_FREE(def->source.extents[i].path);
|
||||||
}
|
}
|
||||||
free(def->source.extents);
|
VIR_FREE(def->source.extents);
|
||||||
|
|
||||||
free(def->target.path);
|
VIR_FREE(def->target.path);
|
||||||
free(def->target.perms.label);
|
VIR_FREE(def->target.perms.label);
|
||||||
free(def);
|
VIR_FREE(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
virStoragePoolDefFree(virStoragePoolDefPtr def) {
|
virStoragePoolDefFree(virStoragePoolDefPtr def) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
free(def->name);
|
VIR_FREE(def->name);
|
||||||
free(def->source.host.name);
|
VIR_FREE(def->source.host.name);
|
||||||
for (i = 0 ; i < def->source.ndevice ; i++) {
|
for (i = 0 ; i < def->source.ndevice ; i++) {
|
||||||
free(def->source.devices[i].freeExtents);
|
VIR_FREE(def->source.devices[i].freeExtents);
|
||||||
free(def->source.devices[i].path);
|
VIR_FREE(def->source.devices[i].path);
|
||||||
}
|
}
|
||||||
free(def->source.devices);
|
VIR_FREE(def->source.devices);
|
||||||
free(def->source.dir);
|
VIR_FREE(def->source.dir);
|
||||||
|
|
||||||
if (def->source.authType == VIR_STORAGE_POOL_AUTH_CHAP) {
|
if (def->source.authType == VIR_STORAGE_POOL_AUTH_CHAP) {
|
||||||
free(def->source.auth.chap.login);
|
VIR_FREE(def->source.auth.chap.login);
|
||||||
free(def->source.auth.chap.passwd);
|
VIR_FREE(def->source.auth.chap.passwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(def->target.path);
|
VIR_FREE(def->target.path);
|
||||||
free(def->target.perms.label);
|
VIR_FREE(def->target.perms.label);
|
||||||
free(def);
|
VIR_FREE(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -114,9 +115,9 @@ virStoragePoolObjFree(virStoragePoolObjPtr obj) {
|
|||||||
if (obj->newDef)
|
if (obj->newDef)
|
||||||
virStoragePoolDefFree(obj->newDef);
|
virStoragePoolDefFree(obj->newDef);
|
||||||
|
|
||||||
free(obj->configFile);
|
VIR_FREE(obj->configFile);
|
||||||
free(obj->autostartLink);
|
VIR_FREE(obj->autostartLink);
|
||||||
free(obj);
|
VIR_FREE(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -225,8 +226,11 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
|
|||||||
char *uuid = NULL;
|
char *uuid = NULL;
|
||||||
char *authType = NULL;
|
char *authType = NULL;
|
||||||
|
|
||||||
if ((ret = calloc(1, sizeof(virStoragePoolDef))) == NULL)
|
if (VIR_ALLOC(ret) < 0) {
|
||||||
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
||||||
|
"%s", _("cannot allocate storage pool"));
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (STRNEQ((const char *)root->name, "pool")) {
|
if (STRNEQ((const char *)root->name, "pool")) {
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
@ -263,17 +267,16 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
|
|||||||
"%s", _("malformed uuid element"));
|
"%s", _("malformed uuid element"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
free(uuid);
|
VIR_FREE(uuid);
|
||||||
uuid = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options->formatFromString) {
|
if (options->formatFromString) {
|
||||||
char *format = virXPathString("string(/pool/source/format/@type)", ctxt);
|
char *format = virXPathString("string(/pool/source/format/@type)", ctxt);
|
||||||
if ((ret->source.format = (options->formatFromString)(conn, format)) < 0) {
|
if ((ret->source.format = (options->formatFromString)(conn, format)) < 0) {
|
||||||
free(format);
|
VIR_FREE(format);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
free(format);
|
VIR_FREE(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_HOST) {
|
if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_HOST) {
|
||||||
@ -292,22 +295,22 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
|
|||||||
"%s", _("cannot extract source devices"));
|
"%s", _("cannot extract source devices"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if ((ret->source.devices = calloc(nsource, sizeof(*ret->source.devices))) == NULL) {
|
if (VIR_ALLOC_N(ret->source.devices, nsource) < 0) {
|
||||||
free(nodeset);
|
VIR_FREE(nodeset);
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("device"));
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("device"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
for (i = 0 ; i < nsource ; i++) {
|
for (i = 0 ; i < nsource ; i++) {
|
||||||
xmlChar *path = xmlGetProp(nodeset[i], BAD_CAST "path");
|
xmlChar *path = xmlGetProp(nodeset[i], BAD_CAST "path");
|
||||||
if (path == NULL) {
|
if (path == NULL) {
|
||||||
free(nodeset);
|
VIR_FREE(nodeset);
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
"%s", _("missing source device path"));
|
"%s", _("missing source device path"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
ret->source.devices[i].path = (char *)path;
|
ret->source.devices[i].path = (char *)path;
|
||||||
}
|
}
|
||||||
free(nodeset);
|
VIR_FREE(nodeset);
|
||||||
ret->source.ndevice = nsource;
|
ret->source.ndevice = nsource;
|
||||||
}
|
}
|
||||||
if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_DIR) {
|
if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_DIR) {
|
||||||
@ -329,12 +332,10 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
|
|||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
_("unknown auth type '%s'"),
|
_("unknown auth type '%s'"),
|
||||||
(const char *)authType);
|
(const char *)authType);
|
||||||
free(authType);
|
VIR_FREE(authType);
|
||||||
authType = NULL;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
free(authType);
|
VIR_FREE(authType);
|
||||||
authType = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret->source.authType == VIR_STORAGE_POOL_AUTH_CHAP) {
|
if (ret->source.authType == VIR_STORAGE_POOL_AUTH_CHAP) {
|
||||||
@ -354,7 +355,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
free(uuid);
|
VIR_FREE(uuid);
|
||||||
xmlFree(type);
|
xmlFree(type);
|
||||||
virStoragePoolDefFree(ret);
|
virStoragePoolDefFree(ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -649,8 +650,11 @@ virStorageVolDefParseDoc(virConnectPtr conn,
|
|||||||
if (options == NULL)
|
if (options == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((ret = calloc(1, sizeof(virStorageVolDef))) == NULL)
|
if (VIR_ALLOC(ret) < 0) {
|
||||||
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
||||||
|
"%s", _("cannot allocate storage vol"));
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (STRNEQ((const char *)root->name, "volume")) {
|
if (STRNEQ((const char *)root->name, "volume")) {
|
||||||
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
virStorageReportError(conn, VIR_ERR_XML_ERROR,
|
||||||
@ -677,20 +681,16 @@ virStorageVolDefParseDoc(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
if (virStorageSize(conn, unit, capacity, &ret->capacity) < 0)
|
if (virStorageSize(conn, unit, capacity, &ret->capacity) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
free(capacity);
|
VIR_FREE(capacity);
|
||||||
capacity = NULL;
|
VIR_FREE(unit);
|
||||||
free(unit);
|
|
||||||
unit = NULL;
|
|
||||||
|
|
||||||
allocation = virXPathString("string(/volume/allocation)", ctxt);
|
allocation = virXPathString("string(/volume/allocation)", ctxt);
|
||||||
if (allocation) {
|
if (allocation) {
|
||||||
unit = virXPathString("string(/volume/allocation/@unit)", ctxt);
|
unit = virXPathString("string(/volume/allocation/@unit)", ctxt);
|
||||||
if (virStorageSize(conn, unit, allocation, &ret->allocation) < 0)
|
if (virStorageSize(conn, unit, allocation, &ret->allocation) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
free(allocation);
|
VIR_FREE(allocation);
|
||||||
allocation = NULL;
|
VIR_FREE(unit);
|
||||||
free(unit);
|
|
||||||
unit = NULL;
|
|
||||||
} else {
|
} else {
|
||||||
ret->allocation = ret->capacity;
|
ret->allocation = ret->capacity;
|
||||||
}
|
}
|
||||||
@ -699,10 +699,10 @@ virStorageVolDefParseDoc(virConnectPtr conn,
|
|||||||
if (options->formatFromString) {
|
if (options->formatFromString) {
|
||||||
char *format = virXPathString("string(/volume/target/format/@type)", ctxt);
|
char *format = virXPathString("string(/volume/target/format/@type)", ctxt);
|
||||||
if ((ret->target.format = (options->formatFromString)(conn, format)) < 0) {
|
if ((ret->target.format = (options->formatFromString)(conn, format)) < 0) {
|
||||||
free(format);
|
VIR_FREE(format);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
free(format);
|
VIR_FREE(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virStorageVolDefParsePerms(conn, ctxt, &ret->target.perms) < 0)
|
if (virStorageVolDefParsePerms(conn, ctxt, &ret->target.perms) < 0)
|
||||||
@ -711,9 +711,9 @@ virStorageVolDefParseDoc(virConnectPtr conn,
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
free(allocation);
|
VIR_FREE(allocation);
|
||||||
free(capacity);
|
VIR_FREE(capacity);
|
||||||
free(unit);
|
VIR_FREE(unit);
|
||||||
virStorageVolDefFree(ret);
|
virStorageVolDefFree(ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -772,6 +772,7 @@ virStorageVolDefFormat(virConnectPtr conn,
|
|||||||
virStorageVolDefPtr def) {
|
virStorageVolDefPtr def) {
|
||||||
virStorageBackendVolOptionsPtr options;
|
virStorageBackendVolOptionsPtr options;
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
options = virStorageBackendVolOptionsForType(pool->type);
|
options = virStorageBackendVolOptionsForType(pool->type);
|
||||||
if (options == NULL)
|
if (options == NULL)
|
||||||
@ -849,7 +850,8 @@ virStorageVolDefFormat(virConnectPtr conn,
|
|||||||
no_memory:
|
no_memory:
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("xml"));
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("xml"));
|
||||||
cleanup:
|
cleanup:
|
||||||
free(virBufferContentAndReset(&buf));
|
tmp = virBufferContentAndReset(&buf);
|
||||||
|
VIR_FREE(tmp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -955,7 +957,7 @@ virStoragePoolObjAssignDef(virConnectPtr conn,
|
|||||||
return pool;
|
return pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(pool = calloc(1, sizeof(virStoragePoolObj)))) {
|
if (VIR_ALLOC(pool) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
||||||
"%s", _("pool"));
|
"%s", _("pool"));
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1063,7 +1065,7 @@ virStoragePoolObjScanConfigs(virStorageDriverStatePtr driver) {
|
|||||||
|
|
||||||
virStoragePoolObjLoad(driver, entry->d_name, path, xml, autostartLink);
|
virStoragePoolObjLoad(driver, entry->d_name, path, xml, autostartLink);
|
||||||
|
|
||||||
free(xml);
|
VIR_FREE(xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
@ -1108,15 +1110,13 @@ virStoragePoolObjSaveDef(virConnectPtr conn,
|
|||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("cannot construct "
|
"%s", _("cannot construct "
|
||||||
"autostart link path"));
|
"autostart link path"));
|
||||||
free(pool->configFile);
|
VIR_FREE(pool->configFile);
|
||||||
pool->configFile = NULL;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!(pool->autostartLink = strdup(path))) {
|
if (!(pool->autostartLink = strdup(path))) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
||||||
"%s", _("config file"));
|
"%s", _("config file"));
|
||||||
free(pool->configFile);
|
VIR_FREE(pool->configFile);
|
||||||
pool->configFile = NULL;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1157,7 +1157,7 @@ virStoragePoolObjSaveDef(virConnectPtr conn,
|
|||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
free(xml);
|
VIR_FREE(xml);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "storage_driver.h"
|
#include "storage_driver.h"
|
||||||
#include "storage_conf.h"
|
#include "storage_conf.h"
|
||||||
|
#include "memory.h"
|
||||||
#include "storage_backend.h"
|
#include "storage_backend.h"
|
||||||
|
|
||||||
#define storageLog(msg...) fprintf(stderr, msg)
|
#define storageLog(msg...) fprintf(stderr, msg)
|
||||||
@ -104,9 +104,8 @@ storageDriverStartup(void) {
|
|||||||
char *base = NULL;
|
char *base = NULL;
|
||||||
char driverConf[PATH_MAX];
|
char driverConf[PATH_MAX];
|
||||||
|
|
||||||
if (!(driverState = calloc(1, sizeof(virStorageDriverState)))) {
|
if (VIR_ALLOC(driverState) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
if (!uid) {
|
if (!uid) {
|
||||||
if ((base = strdup (SYSCONF_DIR "/libvirt")) == NULL)
|
if ((base = strdup (SYSCONF_DIR "/libvirt")) == NULL)
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
|
|
||||||
#include "buf.h"
|
#include "buf.h"
|
||||||
#include "capabilities.h"
|
#include "capabilities.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
|
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
|
||||||
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
|
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
|
||||||
@ -223,17 +224,17 @@ typedef struct xen_v2s4_availheap xen_v2s4_availheap;
|
|||||||
|
|
||||||
#define XEN_GETDOMAININFOLIST_ALLOC(domlist, size) \
|
#define XEN_GETDOMAININFOLIST_ALLOC(domlist, size) \
|
||||||
(hypervisor_version < 2 ? \
|
(hypervisor_version < 2 ? \
|
||||||
((domlist.v0 = malloc(sizeof(*domlist.v0)*(size))) != NULL) : \
|
(VIR_ALLOC_N(domlist.v0, (size)) == 0) : \
|
||||||
(dom_interface_version < 5 ? \
|
(dom_interface_version < 5 ? \
|
||||||
((domlist.v2 = malloc(sizeof(*domlist.v2)*(size))) != NULL) : \
|
(VIR_ALLOC_N(domlist.v2, (size)) == 0) : \
|
||||||
((domlist.v2d5 = malloc(sizeof(*domlist.v2d5)*(size))) != NULL)))
|
(VIR_ALLOC_N(domlist.v2d5, (size)) == 0)))
|
||||||
|
|
||||||
#define XEN_GETDOMAININFOLIST_FREE(domlist) \
|
#define XEN_GETDOMAININFOLIST_FREE(domlist) \
|
||||||
(hypervisor_version < 2 ? \
|
(hypervisor_version < 2 ? \
|
||||||
free(domlist.v0) : \
|
VIR_FREE(domlist.v0) : \
|
||||||
(dom_interface_version < 5 ? \
|
(dom_interface_version < 5 ? \
|
||||||
free(domlist.v2) : \
|
VIR_FREE(domlist.v2) : \
|
||||||
free(domlist.v2d5)))
|
VIR_FREE(domlist.v2d5)))
|
||||||
|
|
||||||
#define XEN_GETDOMAININFOLIST_CLEAR(domlist, size) \
|
#define XEN_GETDOMAININFOLIST_CLEAR(domlist, size) \
|
||||||
(hypervisor_version < 2 ? \
|
(hypervisor_version < 2 ? \
|
||||||
@ -796,8 +797,7 @@ virXenPerror (virConnectPtr conn, const char *msg)
|
|||||||
{
|
{
|
||||||
char *msg_s;
|
char *msg_s;
|
||||||
|
|
||||||
msg_s = malloc (strlen (msg) + 10);
|
if (VIR_ALLOC_N(msg_s, strlen (msg) + 10) == 0) {
|
||||||
if (msg_s) {
|
|
||||||
strcpy (msg_s, msg);
|
strcpy (msg_s, msg);
|
||||||
strcat (msg_s, ": %s");
|
strcat (msg_s, ": %s");
|
||||||
}
|
}
|
||||||
@ -1659,8 +1659,7 @@ virXen_setvcpumap(int handle, int id, unsigned int vcpu,
|
|||||||
/* The allocated memory to cpumap must be 'sizeof(uint64_t)' byte *
|
/* The allocated memory to cpumap must be 'sizeof(uint64_t)' byte *
|
||||||
* for Xen, and also nr_cpus must be 'sizeof(uint64_t) * 8' */
|
* for Xen, and also nr_cpus must be 'sizeof(uint64_t) * 8' */
|
||||||
if (maplen < 8) {
|
if (maplen < 8) {
|
||||||
new = calloc(1, sizeof(uint64_t));
|
if (VIR_ALLOC_N(new, sizeof(uint64_t)) < 0) {
|
||||||
if (!new) {
|
|
||||||
virXenErrorFunc(NULL, VIR_ERR_NO_MEMORY, __FUNCTION__,
|
virXenErrorFunc(NULL, VIR_ERR_NO_MEMORY, __FUNCTION__,
|
||||||
"allocating private data", 0);
|
"allocating private data", 0);
|
||||||
return (-1);
|
return (-1);
|
||||||
@ -1683,7 +1682,7 @@ virXen_setvcpumap(int handle, int id, unsigned int vcpu,
|
|||||||
op.u.setvcpumapd5.cpumap.nr_cpus = nr_cpus;
|
op.u.setvcpumapd5.cpumap.nr_cpus = nr_cpus;
|
||||||
}
|
}
|
||||||
ret = xenHypervisorDoV2Dom(handle, &op);
|
ret = xenHypervisorDoV2Dom(handle, &op);
|
||||||
free(new);
|
VIR_FREE(new);
|
||||||
|
|
||||||
if (unlock_pages(cpumap, maplen) < 0) {
|
if (unlock_pages(cpumap, maplen) < 0) {
|
||||||
virXenError(NULL, VIR_ERR_XEN_CALL, " release", maplen);
|
virXenError(NULL, VIR_ERR_XEN_CALL, " release", maplen);
|
||||||
@ -1985,8 +1984,7 @@ xenHypervisorInit(void)
|
|||||||
*/
|
*/
|
||||||
hypervisor_version = 2;
|
hypervisor_version = 2;
|
||||||
|
|
||||||
ipt = malloc(sizeof(*ipt));
|
if (VIR_ALLOC(ipt) < 0) {
|
||||||
if (ipt == NULL){
|
|
||||||
virXenError(NULL, VIR_ERR_NO_MEMORY, __FUNCTION__, 0);
|
virXenError(NULL, VIR_ERR_NO_MEMORY, __FUNCTION__, 0);
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
@ -2053,13 +2051,13 @@ xenHypervisorInit(void)
|
|||||||
virXenError(NULL, VIR_ERR_XEN_CALL, " ioctl ", IOCTL_PRIVCMD_HYPERCALL);
|
virXenError(NULL, VIR_ERR_XEN_CALL, " ioctl ", IOCTL_PRIVCMD_HYPERCALL);
|
||||||
close(fd);
|
close(fd);
|
||||||
in_init = 0;
|
in_init = 0;
|
||||||
free(ipt);
|
VIR_FREE(ipt);
|
||||||
return(-1);
|
return(-1);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
close(fd);
|
close(fd);
|
||||||
in_init = 0;
|
in_init = 0;
|
||||||
free(ipt);
|
VIR_FREE(ipt);
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2647,7 +2645,7 @@ xenHypervisorLookupDomainByID(virConnectPtr conn,
|
|||||||
ret = virGetDomain(conn, name, XEN_GETDOMAININFO_UUID(dominfo));
|
ret = virGetDomain(conn, name, XEN_GETDOMAININFO_UUID(dominfo));
|
||||||
if (ret)
|
if (ret)
|
||||||
ret->id = id;
|
ret->id = id;
|
||||||
free(name);
|
VIR_FREE(name);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2714,7 +2712,7 @@ xenHypervisorLookupDomainByUUID(virConnectPtr conn,
|
|||||||
ret = virGetDomain(conn, name, uuid);
|
ret = virGetDomain(conn, name, uuid);
|
||||||
if (ret)
|
if (ret)
|
||||||
ret->id = id;
|
ret->id = id;
|
||||||
free(name);
|
VIR_FREE(name);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include "xm_internal.h"
|
#include "xm_internal.h"
|
||||||
#include "xml.h"
|
#include "xml.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt,__VA_ARGS__)
|
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt,__VA_ARGS__)
|
||||||
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
|
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
|
||||||
@ -172,15 +173,13 @@ xenDomainUsedCpus(virDomainPtr dom)
|
|||||||
if (xenUnifiedNodeGetInfo(dom->conn, &nodeinfo) < 0)
|
if (xenUnifiedNodeGetInfo(dom->conn, &nodeinfo) < 0)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
|
||||||
cpulist = calloc(nb_cpu, sizeof(*cpulist));
|
if (VIR_ALLOC_N(cpulist, nb_cpu) < 0)
|
||||||
if (cpulist == NULL)
|
|
||||||
goto done;
|
goto done;
|
||||||
cpuinfo = malloc(sizeof(*cpuinfo) * nb_vcpu);
|
if (VIR_ALLOC_N(cpuinfo, nb_vcpu) < 0)
|
||||||
if (cpuinfo == NULL)
|
|
||||||
goto done;
|
goto done;
|
||||||
cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
|
cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
|
||||||
cpumap = (unsigned char *) calloc(nb_vcpu, cpumaplen);
|
if (xalloc_oversized(nb_vcpu, cpumaplen) ||
|
||||||
if (cpumap == NULL)
|
VIR_ALLOC_N(cpumap, nb_vcpu * cpumaplen) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
if ((ncpus = xenUnifiedDomainGetVcpus(dom, cpuinfo, nb_vcpu,
|
if ((ncpus = xenUnifiedDomainGetVcpus(dom, cpuinfo, nb_vcpu,
|
||||||
@ -202,9 +201,9 @@ xenDomainUsedCpus(virDomainPtr dom)
|
|||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
free(cpulist);
|
VIR_FREE(cpulist);
|
||||||
free(cpumap);
|
VIR_FREE(cpumap);
|
||||||
free(cpuinfo);
|
VIR_FREE(cpuinfo);
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,8 +261,7 @@ xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int f
|
|||||||
return VIR_DRV_OPEN_DECLINED;
|
return VIR_DRV_OPEN_DECLINED;
|
||||||
|
|
||||||
/* Allocate per-connection private data. */
|
/* Allocate per-connection private data. */
|
||||||
priv = calloc (1, sizeof *priv);
|
if (VIR_ALLOC(priv) < 0) {
|
||||||
if (!priv) {
|
|
||||||
xenUnifiedError (NULL, VIR_ERR_NO_MEMORY, "allocating private data");
|
xenUnifiedError (NULL, VIR_ERR_NO_MEMORY, "allocating private data");
|
||||||
return VIR_DRV_OPEN_ERROR;
|
return VIR_DRV_OPEN_ERROR;
|
||||||
}
|
}
|
||||||
@ -342,7 +340,7 @@ xenUnifiedOpen (virConnectPtr conn, xmlURIPtr uri, virConnectAuthPtr auth, int f
|
|||||||
DEBUG0("Failed to activate a mandatory sub-driver");
|
DEBUG0("Failed to activate a mandatory sub-driver");
|
||||||
for (i = 0 ; i < XEN_UNIFIED_NR_DRIVERS ; i++)
|
for (i = 0 ; i < XEN_UNIFIED_NR_DRIVERS ; i++)
|
||||||
if (priv->opened[i]) drivers[i]->close(conn);
|
if (priv->opened[i]) drivers[i]->close(conn);
|
||||||
free(priv);
|
VIR_FREE(priv);
|
||||||
return VIR_DRV_OPEN_ERROR;
|
return VIR_DRV_OPEN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -961,7 +959,7 @@ xenUnifiedDomainDumpXML (virDomainPtr dom, int flags)
|
|||||||
char *cpus, *res;
|
char *cpus, *res;
|
||||||
cpus = xenDomainUsedCpus(dom);
|
cpus = xenDomainUsedCpus(dom);
|
||||||
res = xenDaemonDomainDumpXML(dom, flags, cpus);
|
res = xenDaemonDomainDumpXML(dom, flags, cpus);
|
||||||
free(cpus);
|
VIR_FREE(cpus);
|
||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
if (priv->opened[XEN_UNIFIED_PROXY_OFFSET])
|
if (priv->opened[XEN_UNIFIED_PROXY_OFFSET])
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <malloc.h>
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
67
src/xmlrpc.c
67
src/xmlrpc.c
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "xmlrpc.h"
|
#include "xmlrpc.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "memory.h"
|
||||||
|
|
||||||
#include <libxml/nanohttp.h>
|
#include <libxml/nanohttp.h>
|
||||||
|
|
||||||
@ -47,9 +48,8 @@ static void xmlRpcError(virErrorNumber error, const char *info, int value)
|
|||||||
|
|
||||||
static xmlRpcValuePtr xmlRpcValueNew(xmlRpcValueType type)
|
static xmlRpcValuePtr xmlRpcValueNew(xmlRpcValueType type)
|
||||||
{
|
{
|
||||||
xmlRpcValuePtr ret = malloc(sizeof(*ret));
|
xmlRpcValuePtr ret = NULL;
|
||||||
|
if (VIR_ALLOC(ret) < 0)
|
||||||
if (!ret)
|
|
||||||
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate value"), sizeof(*ret));
|
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate value"), sizeof(*ret));
|
||||||
else
|
else
|
||||||
ret->kind = type;
|
ret->kind = type;
|
||||||
@ -115,7 +115,7 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalInteger(xmlNodePtr node)
|
|||||||
|
|
||||||
if (ret && value)
|
if (ret && value)
|
||||||
ret->value.integer = atoi(value);
|
ret->value.integer = atoi(value);
|
||||||
free(value);
|
VIR_FREE(value);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalBoolean(xmlNodePtr node)
|
|||||||
ret->value.boolean = true;
|
ret->value.boolean = true;
|
||||||
else
|
else
|
||||||
ret->value.boolean = false;
|
ret->value.boolean = false;
|
||||||
free(value);
|
VIR_FREE(value);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalDouble(xmlNodePtr node)
|
|||||||
|
|
||||||
if (ret && value)
|
if (ret && value)
|
||||||
ret->value.real = atof(value);
|
ret->value.real = atof(value);
|
||||||
free(value);
|
VIR_FREE(value);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,11 +158,10 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalArray(xmlNodePtr node)
|
|||||||
for (cur = xmlFirstElement(node); cur; cur = xmlNextElement(cur))
|
for (cur = xmlFirstElement(node); cur; cur = xmlNextElement(cur))
|
||||||
n_elements += 1;
|
n_elements += 1;
|
||||||
|
|
||||||
elems = malloc(n_elements * sizeof(*elems));
|
if (VIR_ALLOC_N(elems, n_elements) < 0) {
|
||||||
if (!elems) {
|
|
||||||
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate value array"),
|
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate value array"),
|
||||||
n_elements * sizeof(*elems));
|
n_elements * sizeof(*elems));
|
||||||
free(ret);
|
VIR_FREE(ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
n_elements = 0;
|
n_elements = 0;
|
||||||
@ -179,10 +178,10 @@ static xmlRpcValuePtr xmlRpcValueUnmarshalArray(xmlNodePtr node)
|
|||||||
|
|
||||||
static xmlRpcValueDictElementPtr xmlRpcValueUnmarshalDictElement(xmlNodePtr node)
|
static xmlRpcValueDictElementPtr xmlRpcValueUnmarshalDictElement(xmlNodePtr node)
|
||||||
{
|
{
|
||||||
xmlRpcValueDictElementPtr ret = malloc(sizeof(*ret));
|
xmlRpcValueDictElementPtr ret;
|
||||||
xmlNodePtr cur;
|
xmlNodePtr cur;
|
||||||
|
|
||||||
if (!ret) {
|
if (VIR_ALLOC(ret) < 0) {
|
||||||
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate dict"), sizeof(*ret));
|
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate dict"), sizeof(*ret));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -195,10 +194,10 @@ static xmlRpcValueDictElementPtr xmlRpcValueUnmarshalDictElement(xmlNodePtr node
|
|||||||
ret->value = xmlRpcValueUnmarshal(cur);
|
ret->value = xmlRpcValueUnmarshal(cur);
|
||||||
} else {
|
} else {
|
||||||
xmlRpcError(VIR_ERR_XML_ERROR, _("unexpected dict node"), 0);
|
xmlRpcError(VIR_ERR_XML_ERROR, _("unexpected dict node"), 0);
|
||||||
free(ret->name);
|
VIR_FREE(ret->name);
|
||||||
if (ret->value)
|
if (ret->value)
|
||||||
xmlRpcValueFree(ret->value);
|
xmlRpcValueFree(ret->value);
|
||||||
free(ret);
|
VIR_FREE(ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -283,26 +282,26 @@ void xmlRpcValueFree(xmlRpcValuePtr value)
|
|||||||
case XML_RPC_ARRAY:
|
case XML_RPC_ARRAY:
|
||||||
for (i = 0; i < value->value.array.n_elements; i++)
|
for (i = 0; i < value->value.array.n_elements; i++)
|
||||||
xmlRpcValueFree(value->value.array.elements[i]);
|
xmlRpcValueFree(value->value.array.elements[i]);
|
||||||
free(value->value.array.elements);
|
VIR_FREE(value->value.array.elements);
|
||||||
break;
|
break;
|
||||||
case XML_RPC_STRUCT:
|
case XML_RPC_STRUCT:
|
||||||
next = value->value.dict.root;
|
next = value->value.dict.root;
|
||||||
while (next) {
|
while (next) {
|
||||||
cur = next;
|
cur = next;
|
||||||
next = next->next;
|
next = next->next;
|
||||||
free(cur->name);
|
VIR_FREE(cur->name);
|
||||||
xmlRpcValueFree(cur->value);
|
xmlRpcValueFree(cur->value);
|
||||||
free(cur);
|
VIR_FREE(cur);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case XML_RPC_STRING:
|
case XML_RPC_STRING:
|
||||||
free(value->value.string);
|
VIR_FREE(value->value.string);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(value);
|
VIR_FREE(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void xmlRpcValueMarshal(xmlRpcValuePtr value, virBufferPtr buf, int indent)
|
void xmlRpcValueMarshal(xmlRpcValuePtr value, virBufferPtr buf, int indent)
|
||||||
@ -436,15 +435,14 @@ static char *xmlRpcCallRaw(const char *url, const char *request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
len = xmlNanoHTTPContentLength(cxt);
|
len = xmlNanoHTTPContentLength(cxt);
|
||||||
response = malloc(len + 1);
|
if (VIR_ALLOC_N(response, len + 1) < 0) {
|
||||||
if (response == NULL) {
|
|
||||||
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate response"), len);
|
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate response"), len);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
ret = xmlNanoHTTPRead(cxt, response, len);
|
ret = xmlNanoHTTPRead(cxt, response, len);
|
||||||
if (ret != len) {
|
if (ret != len) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
free(response);
|
VIR_FREE(response);
|
||||||
response = NULL;
|
response = NULL;
|
||||||
xmlRpcError(VIR_ERR_POST_FAILED, _("read response"), 0);
|
xmlRpcError(VIR_ERR_POST_FAILED, _("read response"), 0);
|
||||||
}
|
}
|
||||||
@ -455,7 +453,7 @@ static char *xmlRpcCallRaw(const char *url, const char *request)
|
|||||||
serrno = errno;
|
serrno = errno;
|
||||||
if (cxt) {
|
if (cxt) {
|
||||||
xmlNanoHTTPClose(cxt);
|
xmlNanoHTTPClose(cxt);
|
||||||
free(contentType);
|
VIR_FREE(contentType);
|
||||||
}
|
}
|
||||||
errno = serrno;
|
errno = serrno;
|
||||||
|
|
||||||
@ -477,7 +475,7 @@ static char **xmlRpcStringArray(xmlRpcValuePtr value)
|
|||||||
if (value->value.array.elements[i]->kind == XML_RPC_STRING)
|
if (value->value.array.elements[i]->kind == XML_RPC_STRING)
|
||||||
size += strlen(value->value.array.elements[i]->value.string) + 1;
|
size += strlen(value->value.array.elements[i]->value.string) + 1;
|
||||||
|
|
||||||
if (!(ptr = malloc(size))) {
|
if (VIR_ALLOC_N(ptr, size) < 0) {
|
||||||
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate string array"), size);
|
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate string array"), size);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -507,7 +505,7 @@ xmlRpcArgvNew(const char *fmt, va_list ap, int *argc)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
*argc = strlen(fmt);
|
*argc = strlen(fmt);
|
||||||
if (!(argv = malloc(sizeof(*argv) * *argc))) {
|
if (VIR_ALLOC_N(argv, *argc) < 0) {
|
||||||
xmlRpcError(VIR_ERR_NO_MEMORY, _("read response"), sizeof(*argv) * *argc);
|
xmlRpcError(VIR_ERR_NO_MEMORY, _("read response"), sizeof(*argv) * *argc);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -552,7 +550,7 @@ xmlRpcArgvFree(int argc, xmlRpcValuePtr *argv)
|
|||||||
for (i = 0; i < argc; i++)
|
for (i = 0; i < argc; i++)
|
||||||
xmlRpcValueFree(argv[i]);
|
xmlRpcValueFree(argv[i]);
|
||||||
|
|
||||||
free(argv);
|
VIR_FREE(argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
int xmlRpcCall(xmlRpcContextPtr context, const char *method,
|
int xmlRpcCall(xmlRpcContextPtr context, const char *method,
|
||||||
@ -589,7 +587,7 @@ int xmlRpcCall(xmlRpcContextPtr context, const char *method,
|
|||||||
|
|
||||||
content = virBufferContentAndReset(&buf);
|
content = virBufferContentAndReset(&buf);
|
||||||
ret = xmlRpcCallRaw(context->uri, content);
|
ret = xmlRpcCallRaw(context->uri, content);
|
||||||
free(content);
|
VIR_FREE(content);
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
return -1;
|
return -1;
|
||||||
@ -597,7 +595,7 @@ int xmlRpcCall(xmlRpcContextPtr context, const char *method,
|
|||||||
xml = xmlReadDoc((const xmlChar *)ret, "response.xml", NULL,
|
xml = xmlReadDoc((const xmlChar *)ret, "response.xml", NULL,
|
||||||
XML_PARSE_NOENT | XML_PARSE_NONET |
|
XML_PARSE_NOENT | XML_PARSE_NONET |
|
||||||
XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
|
XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
|
||||||
free(ret);
|
VIR_FREE(ret);
|
||||||
|
|
||||||
if (xml == NULL) {
|
if (xml == NULL) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
@ -659,13 +657,14 @@ int xmlRpcCall(xmlRpcContextPtr context, const char *method,
|
|||||||
|
|
||||||
xmlRpcContextPtr xmlRpcContextNew(const char *uri)
|
xmlRpcContextPtr xmlRpcContextNew(const char *uri)
|
||||||
{
|
{
|
||||||
xmlRpcContextPtr ret = malloc(sizeof(*ret));
|
xmlRpcContextPtr ret;
|
||||||
|
|
||||||
if (ret) {
|
if (VIR_ALLOC(ret) < 0) {
|
||||||
|
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate new context"), sizeof(*ret));
|
||||||
|
} else {
|
||||||
ret->uri = strdup(uri);
|
ret->uri = strdup(uri);
|
||||||
ret->faultMessage = NULL;
|
ret->faultMessage = NULL;
|
||||||
} else
|
}
|
||||||
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate new context"), sizeof(*ret));
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -673,9 +672,9 @@ xmlRpcContextPtr xmlRpcContextNew(const char *uri)
|
|||||||
void xmlRpcContextFree(xmlRpcContextPtr context)
|
void xmlRpcContextFree(xmlRpcContextPtr context)
|
||||||
{
|
{
|
||||||
if (context) {
|
if (context) {
|
||||||
free(context->uri);
|
VIR_FREE(context->uri);
|
||||||
free(context->faultMessage);
|
VIR_FREE(context->faultMessage);
|
||||||
free(context);
|
VIR_FREE(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user