@@ -37,7 +37,12 @@ static bool get_dmi_data( uint8_t **buffer, size_t *size )
3737 if (* buffer == NULL )
3838 return false;
3939 // retrieve the SMBIOS table
40- return (* size == GetSystemFirmwareTable (signature , 0 , * buffer , * size ))
40+ if (* size != GetSystemFirmwareTable (signature , 0 , * buffer , * size ))
41+ {
42+ free (* buffer );
43+ return false;
44+ }
45+ return true;
4146}
4247
4348#else
@@ -60,15 +65,21 @@ static bool get_dmi_data( const char *path, uint8_t **buffer, size_t *size )
6065 // read SMBIOS structures
6166 input = fopen (fileName , "rb" );
6267 if (input == NULL )
68+ {
69+ free (* buffer );
6370 return false;
71+ }
6472 fread ((char * ) * buffer + 32 , (size_t ) info .st_size , 1 , input );
6573 fclose (input );
6674
6775 // read SMBIOS entry point
6876 snprintf (fileName , sizeof (fileName ), "%s/smbios_entry_point" , path );
6977 input = fopen (fileName , "rb" );
7078 if (input == NULL )
79+ {
80+ free (* buffer );
7181 return false;
82+ }
7283 fread ((char * ) * buffer , 32 , 1 , input );
7384 fclose (input );
7485
@@ -481,15 +492,15 @@ int main(int argc, char ** argv)
481492
482493 if (!result )
483494 {
484- fputs ("Unable to open SMBIOS tables" , stderr );
495+ fputs ("Unable to open SMBIOS tables\n " , stderr );
485496 return 1 ;
486497 }
487498
488499 struct ParserContext parser ;
489500 if (smbios_initialize (& parser , buffer , size , SMBIOS_ANY ) == SMBERR_OK )
490501 printSMBIOS (& parser , stdout );
491502 else
492- fputs ("Invalid SMBIOS data" , stderr );
503+ fputs ("Invalid SMBIOS data\n " , stderr );
493504
494505 free (buffer );
495506 return 0 ;
0 commit comments