From ddecd777bd39ff180d214193871a93ddb47c03ca Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Mon, 21 Feb 2022 23:22:06 -0600 Subject: [PATCH] Fix memory leaks in filesys. --- src/engine/filesys.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/engine/filesys.cpp b/src/engine/filesys.cpp index ecd9e0244..b23f3791d 100644 --- a/src/engine/filesys.cpp +++ b/src/engine/filesys.cpp @@ -513,7 +513,7 @@ static void remove_files_atexit( void ) FILELIST * filelist_new( OBJECT * path ) { - FILELIST * list = (FILELIST *)BJAM_MALLOC( sizeof( FILELIST ) ); + FILELIST * list = b2::jam::make_ptr(); memset( list, 0, sizeof( *list ) ); list->size = 0; @@ -537,13 +537,10 @@ FILELIST * filelist_push_back( FILELIST * list, OBJECT * path ) } - item = (FILEITEM *)BJAM_MALLOC( sizeof( FILEITEM ) ); - memset( item, 0, sizeof( *item ) ); - item->value = (file_info_t *)BJAM_MALLOC( sizeof( file_info_t ) ); + item = b2::jam::make_ptr(); + item->value = b2::jam::make_ptr(); file = item->value; - memset( file, 0, sizeof( *file ) ); - file->name = path; file->files = L0; @@ -575,9 +572,9 @@ FILELIST * filelist_push_front( FILELIST * list, OBJECT * path ) } - item = (FILEITEM *)BJAM_MALLOC( sizeof( FILEITEM ) ); + item = b2::jam::make_ptr(); memset( item, 0, sizeof( *item ) ); - item->value = (file_info_t *)BJAM_MALLOC( sizeof( file_info_t ) ); + item->value = b2::jam::make_ptr(); file = item->value; memset( file, 0, sizeof( *file ) ); @@ -610,15 +607,17 @@ FILELIST * filelist_pop_front( FILELIST * list ) if ( item ) { - if ( item->value ) free_file_info( item->value, 0 ); + if ( item->value ) + { + free_file_info( item->value, 0 ); + b2::jam::free_ptr( item->value ); + } list->head = item->next; list->size--; if ( !list->size ) list->tail = list->head; -#ifdef BJAM_NO_MEM_CACHE - BJAM_FREE( item ); -#endif + b2::jam::free_ptr( item ); } return list; @@ -638,9 +637,7 @@ void filelist_free( FILELIST * list ) while ( filelist_length( list ) ) filelist_pop_front( list ); -#ifdef BJAM_NO_MEM_CACHE - BJAM_FREE( list ); -#endif + b2::jam::free_ptr( list ); } int filelist_empty( FILELIST * list )