Commit f10127ea authored by malenov's avatar malenov
Browse files

check, if .csv has already been opened

parent bee6d5a3
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -1352,11 +1352,16 @@ static void mem_count_summary(void)
void export_mem( const char *csv_filename )
{
    int i;
    FILE *fid;
    static FILE *fid = NULL;
    allocator_record *record_ptr;

    /* Export individual heap memory records to a .csv file */
    if ( csv_filename != NULL && strcmp( csv_filename, "" ) != 0 )
    if (csv_filename == NULL || strcmp( csv_filename, "" ) == 0 )
    {
        return;
    }

    /* Check, if the .csv file has already been opened */
    if ( fid == NULL )
    {
        fid = fopen( csv_filename, "wb" );

@@ -1365,17 +1370,16 @@ void export_mem( const char *csv_filename )
            fprintf( stderr, "\nCannot open %s!\n\n", csv_filename );
            exit( -1 );
        }
    }

    /* Export individual heap memory records to a .csv file */
    for ( i = 0; i < Num_Records; i++ )
    {
        record_ptr = &( allocation_list[i] );
            fprintf( fid, "%s:%d,%ld;\n", record_ptr->name, record_ptr->lineno, record_ptr->block_size );
        fprintf( fid, "%s:%d,%ld;", record_ptr->name, record_ptr->lineno, record_ptr->block_size );
    }
    fprintf( fid, "\n" );

        fclose( fid );
    }

    return;
}
#endif