@@ -1108,7 +1108,7 @@ void add_link( const char *link_name )
11081108
11091109 _new ( link , 1 );
11101110
1111- link -> next = NULL ;
1111+ link -> next = Link_list ;
11121112 Link_list = link ;
11131113 _new ( link -> link_name , strlen ( link_name ) + 1 );
11141114 strcpy ( link -> link_name , link_name );
@@ -1143,6 +1143,19 @@ keyword_def *find_keyword_all( const char *keyword )
11431143 return ( NULL );
11441144}
11451145
1146+ static void free_keyword_list ( void )
1147+ /***********************************/
1148+ {
1149+ keyword_def * key ;
1150+
1151+ while ( (key = Keyword_list ) != NULL ) {
1152+ Keyword_list = key -> next ;
1153+ MemFree ( key -> keyword );
1154+ MemFree ( key -> ctx_list );
1155+ MemFree (key );
1156+ }
1157+ }
1158+
11461159static void add_key_ctx ( keyword_def * key , ctx_def * ctx )
11471160/*******************************************************/
11481161{
@@ -1300,6 +1313,30 @@ ctx_def *find_ctx( const char *ctx_name )
13001313 return ( NULL );
13011314}
13021315
1316+ static void free_ctx_list ( void )
1317+ /*******************************/
1318+ {
1319+ ctx_def * ctx ;
1320+ keylist_def * x1 ;
1321+ section_def * x2 ;
1322+
1323+ while ( (ctx = Ctx_list ) != NULL ) {
1324+ Ctx_list = ctx -> next ;
1325+ while ( (x1 = ctx -> keylist ) != NULL ) {
1326+ ctx -> keylist = x1 -> next ;
1327+ MemFree ( x1 );
1328+ }
1329+ while ( (x2 = ctx -> section_list ) != NULL ) {
1330+ ctx -> section_list = x2 -> next ;
1331+ MemFree ( x2 -> section_text );
1332+ MemFree ( x2 );
1333+ }
1334+ MemFree ( ctx -> title );
1335+ MemFree ( ctx -> ctx_name );
1336+ MemFree ( ctx );
1337+ }
1338+ }
1339+
13031340static char * skip_prep ( char * str )
13041341/*********************************/
13051342{
@@ -1624,6 +1661,22 @@ static void set_browse_numbers( void )
16241661 }
16251662}
16261663
1664+ static void free_browse_list ( void )
1665+ /**********************************/
1666+ {
1667+ browse_def * browse ;
1668+ browse_ctx * x1 ;
1669+
1670+ while ( (browse = Browse_list ) != NULL ) {
1671+ Browse_list = browse -> next ;
1672+ while ( (x1 = browse -> ctx_list ) != NULL ) {
1673+ browse -> ctx_list = x1 -> next ;
1674+ MemFree ( x1 );
1675+ }
1676+ MemFree ( browse );
1677+ }
1678+ }
1679+
16271680static void sort_ctx_list ( void )
16281681/*******************************/
16291682{
@@ -2114,6 +2167,18 @@ static void check_links( void )
21142167 }
21152168}
21162169
2170+ static void free_link_list ( void )
2171+ /********************************/
2172+ {
2173+ link_def * link ;
2174+
2175+ while ( (link = Link_list ) != NULL ) {
2176+ Link_list = link -> next ;
2177+ MemFree ( link -> link_name );
2178+ MemFree ( link );
2179+ }
2180+ }
2181+
21172182void NewList ( const char * ptr , int indent , bool list_indent )
21182183/***********************************************************/
21192184{
@@ -2197,20 +2262,6 @@ int main( int argc, char *argv[] )
21972262 MemInit ();
21982263 file = NULL ;
21992264 if ( setjmp ( Jmp_buf ) ) {
2200- if ( h_file_name != NULL ) {
2201- MemFree ( h_file_name );
2202- }
2203- if ( Header_File != NULL ) {
2204- MemFree ( Header_File );
2205- }
2206- if ( Footer_File != NULL ) {
2207- MemFree ( Footer_File );
2208- }
2209- if ( Help_File != NULL ) {
2210- MemFree ( Help_File );
2211- }
2212- MemFree ( file );
2213-
22142265 if ( Idx_file != NULL ) {
22152266 fclose ( Idx_file );
22162267 }
@@ -2442,8 +2493,25 @@ int main( int argc, char *argv[] )
24422493 if ( Do_hdef ) {
24432494 output_hdef_file ();
24442495 }
2496+ free_link_list ();
2497+ free_keyword_list ();
2498+ free_browse_list ();
2499+ free_ctx_list ();
24452500 rc = 0 ;
24462501 }
2502+ if ( h_file_name != NULL ) {
2503+ MemFree ( h_file_name );
2504+ }
2505+ if ( Header_File != NULL ) {
2506+ MemFree ( Header_File );
2507+ }
2508+ if ( Footer_File != NULL ) {
2509+ MemFree ( Footer_File );
2510+ }
2511+ if ( Help_File != NULL ) {
2512+ MemFree ( Help_File );
2513+ }
2514+ MemFree ( file );
24472515
24482516 MemFini ();
24492517 return ( rc );
0 commit comments