Fix memory leak in cache error path
The llist-based cache() implementations leak memory in the error path - fix that...
libsemanage/src/database_activedb.c +4 -4
@@ -44,7 +44,10 @@ static int dbase_activedb_cache(if (!dbase_llist_needs_resync (handle, &dbase->llist))return STATUS_SUCCESS ; +/* Update cache serial */ dbase_llist_cache_init (&dbase->llist); +if (dbase_llist_set_serial (handle, &dbase->llist) <0 ) + goto err;/* Fetch the entire list */ if (ratable->read_list (handle, &records, &rcount) <0 )
@@ -57,10 +60,6 @@ static int dbase_activedb_cache( rtable->free (records[i]); } -/* Update cache serial */ -if (dbase_llist_set_serial (handle, &dbase->llist) <0 ) - goto err; -free (records);return STATUS_SUCCESS ;
@@ -68,6 +67,7 @@ static int dbase_activedb_cache(ERR (handle,"could not cache active database" );for (; i < rcount; i++) rtable->free (records[i]); +dbase_llist_drop_cache (&dbase->llist);free (records);return STATUS_ERR ; }
libsemanage/src/database_file.c +4 -4
@@ -76,7 +76,10 @@ static int dbase_file_cache(if (!dbase_llist_needs_resync (handle, &dbase->llist))return STATUS_SUCCESS ; +/* Update cache serial */ dbase_llist_cache_init (&dbase->llist); +if (dbase_llist_set_serial (handle, &dbase->llist) <0 ) + goto err;if (construct_filename (handle, dbase, &fname) <0 ) goto err;
@@ -115,10 +118,6 @@ static int dbase_file_cache( }while (pstatus !=STATUS_NODATA ); -/* Update cache serial */ -if (dbase_llist_set_serial (handle, &dbase->llist) <0 ) - goto err; - rtable->free (process_record);parse_close (parse_info);parse_release (parse_info);
@@ -130,6 +129,7 @@ static int dbase_file_cache( rtable->free (process_record);parse_close (parse_info);parse_release (parse_info); +dbase_llist_drop_cache (&dbase->llist);free (fname);return STATUS_ERR ; }
libsemanage/src/database_join.c +4 -0
@@ -58,7 +58,10 @@ static int dbase_join_cache(if (!dbase_llist_needs_resync (handle, &dbase->llist))return STATUS_SUCCESS ; +/* Update cache serial */ dbase_llist_cache_init (&dbase->llist); +if (dbase_llist_set_serial (handle, &dbase->llist) <0 ) + goto err;/* First cache any child dbase, which must * be the first thing done when calling dbase
@@ -157,6 +160,7 @@ static int dbase_join_cache(free (records2); rtable->key_free (rkey); rtable->free (record); +dbase_llist_drop_cache (&dbase->llist);return STATUS_ERR ; }