Skip to content

Commit 33697c4

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

File tree

6 files changed

+13
-4
lines changed

6 files changed

+13
-4
lines changed

libsemanage/src/database_activedb.c

+3
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

+3
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

+3
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ int dbase_join_init(semanage_handle_t * handle,
269269
void dbase_join_release(dbase_join_t * dbase)
270270
{
271271

272+
if (!dbase)
273+
return;
274+
272275
dbase_llist_drop_cache(&dbase->llist);
273276
free(dbase);
274277
}

libsemanage/src/database_policydb.c

+1-1
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

+1
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ int semanage_direct_connect(semanage_handle_t * sh)
319319

320320
err:
321321
ERR(sh, "could not establish direct connection");
322+
(void) semanage_direct_disconnect(sh);
322323
return STATUS_ERR;
323324
}
324325

libsemanage/src/handle.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,11 @@ int semanage_access_check(semanage_handle_t * sh)
365365

366366
int semanage_disconnect(semanage_handle_t * sh)
367367
{
368-
assert(sh != NULL && sh->funcs != NULL
369-
&& sh->funcs->disconnect != NULL);
368+
assert(sh != NULL);
370369
if (!sh->is_connected) {
371370
return 0;
372371
}
373-
if (sh->funcs->disconnect(sh) < 0) {
372+
if (sh->funcs && sh->funcs->disconnect(sh) < 0) {
374373
return -1;
375374
}
376375
sh->is_in_transaction = 0;

0 commit comments

Comments
 (0)