[lib] Use stack-based virSchedParameter to avoid a free() problem.
authorMatthias Bolte <matthias.bolte@googlemail.com>
Tue, 27 Oct 2009 16:13:12 +0000 (17:13 +0100)
committerroot <root@vsc-master.uni-paderborn.de>
Tue, 27 Oct 2009 16:13:12 +0000 (17:13 +0100)
Signed-off-by: Matthias Bolte <matthias.bolte@googlemail.com>

lib/vm.c

index 342582a..1a711fa 100644 (file)
--- a/lib/vm.c
+++ b/lib/vm.c
@@ -379,7 +379,7 @@ _apply_vm_sched_parameters (struct VscError *error, virDomainPtr domain,
 {
        int totalRequestedMhz;
        char *sched_name = NULL;
 {
        int totalRequestedMhz;
        char *sched_name = NULL;
-       virSchedParameterPtr sched_params = NULL;
+       virSchedParameter sched_params[3];
        int num_sched_params = 0;
        char host_ipv4_string[VSC_MGMT__IPV4__STRING_SIZE] = "";
 
        int num_sched_params = 0;
        char host_ipv4_string[VSC_MGMT__IPV4__STRING_SIZE] = "";
 
@@ -390,6 +390,8 @@ _apply_vm_sched_parameters (struct VscError *error, virDomainPtr domain,
        VSC__ASSERT (host != NULL);
 
        /* Prepare scheduler parameters */
        VSC__ASSERT (host != NULL);
 
        /* Prepare scheduler parameters */
+       memset (sched_params, 0, sizeof (virSchedParameter) * 3);
+
        switch (host->info.type) {
        case VSC_MGMT__HOST_TYPE__VIRTUAL:
                /* Do nothing */
        switch (host->info.type) {
        case VSC_MGMT__HOST_TYPE__VIRTUAL:
                /* Do nothing */
@@ -419,12 +421,6 @@ _apply_vm_sched_parameters (struct VscError *error, virDomainPtr domain,
                totalRequestedMhz = resource_config->num_cores * resource_config->core_clock;
                num_sched_params = 2;
 
                totalRequestedMhz = resource_config->num_cores * resource_config->core_clock;
                num_sched_params = 2;
 
-               sched_params = vsc_alloc (error, sizeof(virSchedParameter) * num_sched_params);
-               if (error->occured) {
-                       VSC__APPEND_ERROR0 (error, VSC__ERROR_CODE__TRACE);
-                       goto cleanup;
-               }
-
                snprintf (sched_params[0].field, VIR_DOMAIN_SCHED_FIELD_LENGTH, "%s", "weight");
                sched_params[0].type = VIR_DOMAIN_SCHED_FIELD_UINT;
                sched_params[0].value.ui = 256; /* enforce the default */
                snprintf (sched_params[0].field, VIR_DOMAIN_SCHED_FIELD_LENGTH, "%s", "weight");
                sched_params[0].type = VIR_DOMAIN_SCHED_FIELD_UINT;
                sched_params[0].value.ui = 256; /* enforce the default */
@@ -456,12 +452,6 @@ _apply_vm_sched_parameters (struct VscError *error, virDomainPtr domain,
                totalRequestedMhz = resource_config->num_cores * resource_config->core_clock;
                num_sched_params = 3;
 
                totalRequestedMhz = resource_config->num_cores * resource_config->core_clock;
                num_sched_params = 3;
 
-               sched_params = vsc_alloc (error, sizeof(virSchedParameter) * num_sched_params);
-               if (error->occured) {
-                       VSC__APPEND_ERROR0 (error, VSC__ERROR_CODE__TRACE);
-                       goto cleanup;
-               }
-
                snprintf (sched_params[0].field, VIR_DOMAIN_SCHED_FIELD_LENGTH, "%s", "reservation");
                sched_params[0].type = VIR_DOMAIN_SCHED_FIELD_LLONG;
 
                snprintf (sched_params[0].field, VIR_DOMAIN_SCHED_FIELD_LENGTH, "%s", "reservation");
                sched_params[0].type = VIR_DOMAIN_SCHED_FIELD_LLONG;
 
@@ -489,14 +479,13 @@ _apply_vm_sched_parameters (struct VscError *error, virDomainPtr domain,
        }
 
        /* Apply scheduler parameters */
        }
 
        /* Apply scheduler parameters */
-       if (sched_params != NULL &&
+       if (num_sched_params > 0 &&
            virDomainSetSchedulerParameters (domain, sched_params, num_sched_params) != 0) {
                _ERROR_FROM_LIBVIRT (error, virDomainGetConnect (domain));
                goto cleanup;
        }
 
 cleanup:
            virDomainSetSchedulerParameters (domain, sched_params, num_sched_params) != 0) {
                _ERROR_FROM_LIBVIRT (error, virDomainGetConnect (domain));
                goto cleanup;
        }
 
 cleanup:
-       vsc_free (&sched_params);
        vsc_free (&sched_name);
 }
 
        vsc_free (&sched_name);
 }