libsemanage: fixes from coverity

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
This commit is contained in:
Eric Paris 2012-12-05 15:35:53 -05:00
parent c27a54775d
commit 2276a2fa51
4 changed files with 13 additions and 8 deletions

View File

@ -369,9 +369,11 @@ int dbase_llist_list(semanage_handle_t * handle,
ERR(handle, "out of memory");
err:
for (; i >= 0; i--)
dbase->rtable->free(tmp_records[i]);
free(tmp_records);
if (tmp_records) {
for (; i >= 0; i--)
dbase->rtable->free(tmp_records[i]);
free(tmp_records);
}
ERR(handle, "could not allocate record array");
return STATUS_ERR;
}

View File

@ -462,9 +462,11 @@ static int dbase_policydb_list(semanage_handle_t * handle,
ERR(handle, "out of memory");
err:
for (; list_arg.pos >= 0; list_arg.pos--)
dbase->rtable->free(tmp_records[list_arg.pos]);
free(tmp_records);
if (tmp_records) {
for (; list_arg.pos >= 0; list_arg.pos--)
dbase->rtable->free(tmp_records[list_arg.pos]);
free(tmp_records);
}
ERR(handle, "could not list records");
return STATUS_ERR;
}

View File

@ -62,11 +62,12 @@ void hidden semanage_msg_default_handler(void *varg __attribute__ ((unused)),
switch (semanage_msg_get_level(handle)) {
case SEMANAGE_MSG_ERR:
stream = stderr;
errsv = errno;
break;
case SEMANAGE_MSG_WARN:
stream = stderr;
break;
case SEMANAGE_MSG_INFO:
default:
stream = stdout;
break;

View File

@ -1061,7 +1061,7 @@ int semanage_split_fc(semanage_handle_t * sh)
}
hd = open(semanage_path(SEMANAGE_TMP, SEMANAGE_HOMEDIR_TMPL),
O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (!hd) {
if (hd < 0) {
ERR(sh, "Could not open %s for writing.",
semanage_path(SEMANAGE_TMP, SEMANAGE_HOMEDIR_TMPL));
goto cleanup;