+Thu May 29 11:23:00 EST 2008 Daniel P. Berrange <berrange@redhat.com>
+
+ Misc memory handling / cleanup fixes
+ * src/capabilities.c: Avoiding deferencing NULL pointer in
+ cleanup code
+ * src/qemu_conf.c: Free sound structs on cleanup
+ * src/qparams.c: raise a libvirt error upon OOM
+
Thu May 29 11:12:00 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* tests/testutils.c, tests/testutils.h: Add generic main()
virCapsPtr caps;
if (VIR_ALLOC(caps) < 0)
- goto no_memory;
+ return NULL;
if ((caps->host.arch = strdup(arch)) == NULL)
goto no_memory;
static void
virCapabilitiesFreeHostNUMACell(virCapsHostNUMACellPtr cell)
{
+ if (cell == NULL)
+ return;
+
VIR_FREE(cell->cpus);
VIR_FREE(cell);
}
virCapabilitiesFreeGuestDomain(virCapsGuestDomainPtr dom)
{
int i;
+ if (dom == NULL)
+ return;
+
VIR_FREE(dom->info.emulator);
VIR_FREE(dom->info.loader);
for (i = 0 ; i < dom->info.nmachines ; i++)
static void
virCapabilitiesFreeGuestFeature(virCapsGuestFeaturePtr feature)
{
+ if (feature == NULL)
+ return;
VIR_FREE(feature->name);
VIR_FREE(feature);
}
virCapabilitiesFreeGuest(virCapsGuestPtr guest)
{
int i;
+ if (guest == NULL)
+ return;
+
VIR_FREE(guest->ostype);
VIR_FREE(guest->arch.name);
void
virCapabilitiesFree(virCapsPtr caps) {
int i;
+ if (caps == NULL)
+ return;
for (i = 0 ; i < caps->nguests ; i++)
virCapabilitiesFreeGuest(caps->guests[i]);
struct qemud_vm_input_def *input = def->inputs;
struct qemud_vm_chr_def *serial = def->serials;
struct qemud_vm_chr_def *parallel = def->parallels;
+ struct qemud_vm_sound_def *sound = def->sounds;
while (disk) {
struct qemud_vm_disk_def *prev = disk;
parallel = parallel->next;
free(prev);
}
+ while (sound) {
+ struct qemud_vm_sound_def *prev = sound;
+ sound = sound->next;
+ free(prev);
+ }
xmlFree(def->keymap);
free(def);
}
}
check = check->next;
}
- if (collision)
+ if (collision) {
+ free(sound);
continue;
+ }
def->nsounds++;
sound->next = NULL;
#include "memory.h"
#include "qparams.h"
+static void
+qparam_report_oom(void)
+{
+ const char *virerr = __virErrorMsg(VIR_ERR_NO_MEMORY, NULL);
+ __virRaiseError(NULL, NULL, NULL, VIR_FROM_NONE, VIR_ERR_NO_MEMORY, VIR_ERR_ERROR,
+ virerr, NULL, NULL, -1, -1, virerr, NULL);
+}
+
struct qparam_set *
new_qparam_set (int init_alloc, ...)
{
if (init_alloc <= 0) init_alloc = 1;
- if (VIR_ALLOC(ps) < 0)
+ if (VIR_ALLOC(ps) < 0) {
+ qparam_report_oom();
return NULL;
+ }
ps->n = 0;
ps->alloc = init_alloc;
if (VIR_ALLOC_N(ps->p, ps->alloc) < 0) {
VIR_FREE (ps);
+ qparam_report_oom();
return NULL;
}
{
if (ps->n >= ps->alloc) {
if (VIR_REALLOC_N(ps->p, ps->alloc * 2) < 0) {
- perror ("realloc");
+ qparam_report_oom();
return -1;
}
ps->alloc *= 2;
char *pname, *pvalue;
pname = strdup (name);
- if (!pname)
+ if (!pname) {
+ qparam_report_oom();
return -1;
+ }
pvalue = strdup (value);
if (!pvalue) {
VIR_FREE (pname);
+ qparam_report_oom();
return -1;
}
}
if (virBufferError(&buf)) {
+ qparam_report_oom();
return NULL;
}
const char *end, *eq;
ps = new_qparam_set (0, NULL);
- if (!ps) return NULL;
+ if (!ps) {
+ qparam_report_oom();
+ return NULL;
+ }
if (!query || query[0] == '\0') return ps;
return ps;
out_of_memory:
+ qparam_report_oom();
free_qparam_set (ps);
return NULL;
}