Skip to content

Commit e225321

Browse files
committed
libsemanage: free resources on failed connect attempt
Signed-off-by: Christian Göttsche <[email protected]>
1 parent 2b6b5bd commit e225321

File tree

6 files changed

+13
-4
lines changed

6 files changed

+13
-4
lines changed

libsemanage/src/database_activedb.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ int dbase_activedb_init(semanage_handle_t * handle,
139139
void dbase_activedb_release(dbase_activedb_t * dbase)
140140
{
141141

142+
if (!dbase)
143+
return;
144+
142145
dbase_llist_drop_cache(&dbase->llist);
143146
free(dbase);
144147
}

libsemanage/src/database_file.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ int dbase_file_init(semanage_handle_t * handle,
191191
void dbase_file_release(dbase_file_t * dbase)
192192
{
193193

194+
if (!dbase)
195+
return;
196+
194197
dbase_llist_drop_cache(&dbase->llist);
195198
free(dbase);
196199
}

libsemanage/src/database_join.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ int dbase_join_init(semanage_handle_t * handle,
271271
void dbase_join_release(dbase_join_t * dbase)
272272
{
273273

274+
if (!dbase)
275+
return;
276+
274277
dbase_llist_drop_cache(&dbase->llist);
275278
free(dbase);
276279
}

libsemanage/src/database_policydb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct dbase_policydb {
4444
static void dbase_policydb_drop_cache(dbase_policydb_t * dbase)
4545
{
4646

47-
if (dbase->cache_serial >= 0) {
47+
if (dbase && dbase->cache_serial >= 0) {
4848
sepol_policydb_free(dbase->policydb);
4949
dbase->cache_serial = -1;
5050
dbase->modified = 0;

libsemanage/src/direct_api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ int semanage_direct_connect(semanage_handle_t * sh)
321321

322322
err:
323323
ERR(sh, "could not establish direct connection");
324+
(void) semanage_direct_disconnect(sh);
324325
return STATUS_ERR;
325326
}
326327

libsemanage/src/handle.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,11 @@ int semanage_access_check(semanage_handle_t * sh)
368368

369369
int semanage_disconnect(semanage_handle_t * sh)
370370
{
371-
assert(sh != NULL && sh->funcs != NULL
372-
&& sh->funcs->disconnect != NULL);
371+
assert(sh != NULL);
373372
if (!sh->is_connected) {
374373
return 0;
375374
}
376-
if (sh->funcs->disconnect(sh) < 0) {
375+
if (sh->funcs && sh->funcs->disconnect(sh) < 0) {
377376
return -1;
378377
}
379378
sh->is_in_transaction = 0;

0 commit comments

Comments
 (0)