Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitizer test #321

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Next Next commit
libsemanage: free resources on failed connect attempt
Signed-off-by: Christian Göttsche <[email protected]>
  • Loading branch information
cgzones committed Nov 1, 2023
commit 792af02329ee685d9bb4c5f19b83a2b3ebb7eeb1
3 changes: 3 additions & 0 deletions libsemanage/src/database_activedb.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ int dbase_activedb_init(semanage_handle_t * handle,
void dbase_activedb_release(dbase_activedb_t * dbase)
{

if (!dbase)
return;

dbase_llist_drop_cache(&dbase->llist);
free(dbase);
}
Expand Down
3 changes: 3 additions & 0 deletions libsemanage/src/database_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ int dbase_file_init(semanage_handle_t * handle,
void dbase_file_release(dbase_file_t * dbase)
{

if (!dbase)
return;

dbase_llist_drop_cache(&dbase->llist);
free(dbase);
}
Expand Down
3 changes: 3 additions & 0 deletions libsemanage/src/database_join.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ int dbase_join_init(semanage_handle_t * handle,
void dbase_join_release(dbase_join_t * dbase)
{

if (!dbase)
return;

dbase_llist_drop_cache(&dbase->llist);
free(dbase);
}
Expand Down
2 changes: 1 addition & 1 deletion libsemanage/src/database_policydb.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct dbase_policydb {
static void dbase_policydb_drop_cache(dbase_policydb_t * dbase)
{

if (dbase->cache_serial >= 0) {
if (dbase && dbase->cache_serial >= 0) {
sepol_policydb_free(dbase->policydb);
dbase->cache_serial = -1;
dbase->modified = 0;
Expand Down
1 change: 1 addition & 0 deletions libsemanage/src/direct_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ int semanage_direct_connect(semanage_handle_t * sh)

err:
ERR(sh, "could not establish direct connection");
(void) semanage_direct_disconnect(sh);
return STATUS_ERR;
}

Expand Down
5 changes: 2 additions & 3 deletions libsemanage/src/handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,11 @@ int semanage_access_check(semanage_handle_t * sh)

int semanage_disconnect(semanage_handle_t * sh)
{
assert(sh != NULL && sh->funcs != NULL
&& sh->funcs->disconnect != NULL);
assert(sh != NULL);
if (!sh->is_connected) {
return 0;
}
if (sh->funcs->disconnect(sh) < 0) {
if (sh->funcs && sh->funcs->disconnect(sh) < 0) {
return -1;
}
sh->is_in_transaction = 0;
Expand Down