summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Minar <miminar@redhat.com>2014-06-30 15:14:53 +0200
committerMichal Minar <miminar@redhat.com>2014-07-01 10:06:27 +0200
commit599e084b9be3dabc2c24a3d3fe0c21e378481ecc (patch)
tree9f4a91033d47d2179012c2d7b91742d89183e63f
parentccedb81c289ee52ee5db117c9b1082ef9b6532cb (diff)
downloadopenlmi-providers-599e084b9be3dabc2c24a3d3fe0c21e378481ecc.tar.gz
openlmi-providers-599e084b9be3dabc2c24a3d3fe0c21e378481ecc.tar.xz
openlmi-providers-599e084b9be3dabc2c24a3d3fe0c21e378481ecc.zip
jobmanager: fixed coverity issues
removed unused variables made sure that code works the same in (no)debug mode got rid of double frees
-rw-r--r--src/libs/jobmanager/job_manager.c47
-rw-r--r--src/libs/jobmanager/lmi_job.c24
2 files changed, 32 insertions, 39 deletions
diff --git a/src/libs/jobmanager/job_manager.c b/src/libs/jobmanager/job_manager.c
index bc654d7..2d1f55b 100644
--- a/src/libs/jobmanager/job_manager.c
+++ b/src/libs/jobmanager/job_manager.c
@@ -320,8 +320,10 @@ static gint cmp_job_file_names(gconstpointer a,
guint64 fst_id;
guint64 snd_id;
- g_assert((fst_num_start = rindex(na, '-')) != NULL);
- g_assert((snd_num_start = rindex(nb, '-')) != NULL);
+ fst_num_start = rindex(na, '-');
+ g_assert(fst_num_start != NULL);
+ snd_num_start = rindex(nb, '-');
+ g_assert(snd_num_start != NULL);
++fst_num_start;
++snd_num_start;
fst_id = g_ascii_strtoull(fst_num_start, NULL, 10);
@@ -1546,7 +1548,8 @@ static LmiJob *load_job_from_file(gchar const *job_file_path)
gchar job_type_name[BUFLEN];
const gchar *basename;
- g_assert((tmp = rindex(job_file_path, '-')) != NULL);
+ tmp = rindex(job_file_path, '-');
+ g_assert(tmp != NULL);
if ((basename = rindex(job_file_path, '/')) != NULL) {
++basename;
} else {
@@ -1554,7 +1557,7 @@ static LmiJob *load_job_from_file(gchar const *job_file_path)
}
lmi_debug("Loading job file \"%s\".", basename);
strncpy(job_type_name, basename, MIN(tmp - basename, BUFLEN));
- job_type_name[MIN(tmp - basename, BUFLEN)] = 0;
+ job_type_name[MIN(tmp - basename, BUFLEN - 1)] = 0;
if ((job_type = g_type_from_name(job_type_name)) == 0) {
lmi_error("Job type \"%s\" is not known to glib type system.",
job_type_name);
@@ -2354,22 +2357,17 @@ err:
CMPIStatus jobmgr_run_job(LmiJob *job)
{
CMPIStatus status = {CMPI_RC_OK, NULL};
- const JobTypeInfo *info;
PendingJobKey *job_key = NULL;
gchar *jobid;
+ GSource *source;
g_assert(_initialized_counter);
g_assert(LMI_IS_JOB(job));
- if ((info = lookup_job_type_info_for_job(job)) == NULL) {
- CMSetStatus(&status, CMPI_RC_ERR_FAILED);
- goto err;
- }
-
JM_CRITICAL_CRITICAL_BEGIN;
JOB_CRITICAL_BEGIN(job);
if ((job_key = g_new(PendingJobKey, 1)) == NULL) {
lmi_error("Memory allocation failed");
- goto job_lock_release;
+ goto err;
}
job_key->priority = lmi_job_get_priority(job);
job_key->number = lmi_job_get_number(job);
@@ -2379,23 +2377,21 @@ CMPIStatus jobmgr_run_job(LmiJob *job)
g_free(jobid);
CMSetStatusWithChars(_cb, &status,
CMPI_RC_ERR_FAILED, "Job already started!");
- goto job_key_err;
+ goto err;
}
JOB_CRITICAL_END(job);
g_tree_insert(_job_queue, job_key, job);
- GSource *source = g_idle_source_new();
+ source = g_idle_source_new();
g_source_set_callback(source, launch_jobs, NULL, NULL);
g_source_attach(source, _main_ctx);
JM_CRITICAL_CRITICAL_END;
return status;
-job_key_err:
+err:
g_free(job_key);
-job_lock_release:
JOB_CRITICAL_END(job);
JM_CRITICAL_CRITICAL_END;
-err:
return status;
}
@@ -2532,7 +2528,6 @@ gchar **jobmgr_get_pending_job_ids(guint *count)
return res;
res_err:
- g_free(res);
while (ptr > res)
g_free(*(--ptr));
g_free(res);
@@ -2757,7 +2752,7 @@ LmiJob *jobmgr_get_job_by_name(const gchar *name)
CMPIStatus jobmgr_job_to_cim_op(const LmiJob *job, CMPIObjectPath **op)
{
CMPIStatus status = {CMPI_RC_OK, NULL};
- gchar *namespace = NULL;
+ gchar *namespace;
char instance_id[BUFLEN];
CMPIValue value;
const JobTypeInfo *info;
@@ -2772,10 +2767,10 @@ CMPIStatus jobmgr_job_to_cim_op(const LmiJob *job, CMPIObjectPath **op)
}
if ((namespace = lmi_read_config("CIM", "Namespace")) == NULL)
goto err;
- if ((*op = CMNewObjectPath(_cb, namespace, info->cim_class_name,
- &status)) == NULL || status.rc)
- goto namespace_err;
+ *op = CMNewObjectPath(_cb, namespace, info->cim_class_name, &status);
g_free(namespace);
+ if (*op == NULL || status.rc)
+ goto err;
g_snprintf(instance_id, BUFLEN, "LMI:%s:%u", info->cim_class_name,
lmi_job_get_number(job));
@@ -2794,8 +2789,6 @@ string_err:
CMRelease(value.string);
op_err:
CMRelease(*op);
-namespace_err:
- g_free(namespace);
err:
lmi_error("Memory allocation failed");
if (!status.rc)
@@ -2893,14 +2886,13 @@ CMPIStatus jobmgr_job_to_method_result_instance(const LmiJob *job,
CMPIValue value;
CMPIData data;
gchar buf[BUFLEN];
- const gchar *method_name;
g_assert(instance);
g_assert(LMI_IS_JOB(job));
g_assert(_initialized_counter > 0);
JOB_CRITICAL_BEGIN(job);
- if ((method_name = lmi_job_get_method_name(job)) == NULL) {
+ if (lmi_job_get_method_name(job) == NULL) {
g_snprintf(buf, BUFLEN, "Can't create LMI_MethodResult instance"
" out of job #%u with method-name unset.", lmi_job_get_number(job));
goto err;
@@ -3214,7 +3206,6 @@ CMPIStatus jobmgr_get_job_matching_op(const CMPIObjectPath *path,
{
CMPIStatus status = {CMPI_RC_OK, NULL};
CMPIData data;
- CMPIString *str;
const char *instance_id;
const char *class_name_start;
const char *class_name_end;
@@ -3223,11 +3214,9 @@ CMPIStatus jobmgr_get_job_matching_op(const CMPIObjectPath *path,
LmiJob *jobptr = NULL;
struct _JobTypeSearchContainer jtsc = {NULL, G_TYPE_INVALID};
const JobTypeInfo *info;
- gchar error[BUFLEN];
+ gchar error[BUFLEN] = "";
g_assert(_initialized_counter);
- if ((str = CMGetClassName(path, &status)) == NULL)
- return status;
data = CMGetKey(path, "InstanceID", &status);
if (status.rc)
return status;
diff --git a/src/libs/jobmanager/lmi_job.c b/src/libs/jobmanager/lmi_job.c
index 41a91d4..464bd41 100644
--- a/src/libs/jobmanager/lmi_job.c
+++ b/src/libs/jobmanager/lmi_job.c
@@ -1844,13 +1844,15 @@ gchar **lmi_job_get_in_param_keys(const LmiJob *job)
if (job->priv->in_parameters)
size = g_hash_table_size(job->priv->in_parameters);
res = g_new(gchar *, size + 1);
- if (res && size > 1) {
- g_hash_table_iter_init(&hi, job->priv->in_parameters);
- while (g_hash_table_iter_next(&hi, &key, NULL)) {
- res[index++] = g_strdup((const char *) key);
+ if (res != NULL) {
+ if (size > 1) {
+ g_hash_table_iter_init(&hi, job->priv->in_parameters);
+ while (g_hash_table_iter_next(&hi, &key, NULL)) {
+ res[index++] = g_strdup((const char *) key);
+ }
}
+ res[index] = NULL;
}
- res[index] = NULL;
PRIV_CRITICAL_CRITICAL_END(job->priv);
return res;
@@ -1923,13 +1925,15 @@ gchar **lmi_job_get_out_param_keys(const LmiJob *job)
if (job->priv->out_parameters)
size = g_hash_table_size(job->priv->out_parameters);
res = g_new(gchar *, size + 1);
- if (res && size > 1) {
- g_hash_table_iter_init(&hi, job->priv->out_parameters);
- while (g_hash_table_iter_next(&hi, &key, NULL)) {
- res[index++] = g_strdup((const char *) key);
+ if (res != NULL) {
+ if (size > 1) {
+ g_hash_table_iter_init(&hi, job->priv->out_parameters);
+ while (g_hash_table_iter_next(&hi, &key, NULL)) {
+ res[index++] = g_strdup((const char *) key);
+ }
}
+ res[index] = NULL;
}
- res[index] = NULL;
PRIV_CRITICAL_CRITICAL_END(job->priv);
return res;