diff --git a/libsemanage/src/database_llist.c b/libsemanage/src/database_llist.c index 5f0c1478..53583d46 100644 --- a/libsemanage/src/database_llist.c +++ b/libsemanage/src/database_llist.c @@ -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; } diff --git a/libsemanage/src/database_policydb.c b/libsemanage/src/database_policydb.c index 94850b7f..dbb23b2d 100644 --- a/libsemanage/src/database_policydb.c +++ b/libsemanage/src/database_policydb.c @@ -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; } diff --git a/libsemanage/src/debug.c b/libsemanage/src/debug.c index 90d4b4eb..ea51ffbb 100644 --- a/libsemanage/src/debug.c +++ b/libsemanage/src/debug.c @@ -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; diff --git a/libsemanage/src/semanage_store.c b/libsemanage/src/semanage_store.c index e0628eb6..6d5dd2a0 100644 --- a/libsemanage/src/semanage_store.c +++ b/libsemanage/src/semanage_store.c @@ -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;