Previous 15994 Revisions Next

r8129 Friday 21st May, 2010 at 15:23:17 UTC by Firewave
Fixed memory leaks when trying to use softlist entry with missing roms
[src/mess]softlist.c

src/mess/softlist.c
r8128r8129
168168    from the global pool. So they should be global_free'ed
169169    when they are not used anymore.
170170-------------------------------------------------*/
171static void software_name_split(const char *swlist_swname, char **swlist_name, char **swname, char **swpart )
171static void software_name_split(running_machine* machine, const char *swlist_swname, char **swlist_name, char **swname, char **swpart )
172172{
173173   const char *split_1st_loc = strchr( swlist_swname, ':' );
174174   const char *split_2nd_loc = ( split_1st_loc ) ? strchr( split_1st_loc + 1, ':' ) : NULL;
r8128r8129
182182      if ( split_2nd_loc )
183183      {
184184         int size = split_1st_loc - swlist_swname;
185         *swlist_name = global_alloc_array_clear(char,size+1);
185         *swlist_name = auto_alloc_array_clear(machine,char,size+1);
186186         memcpy( *swlist_name, swlist_swname, size );
187187
188188         size = split_2nd_loc - ( split_1st_loc + 1 );
189         *swname = global_alloc_array_clear(char,size+1);
189         *swname = auto_alloc_array_clear(machine,char,size+1);
190190         memcpy( *swname, split_1st_loc + 1, size );
191191
192192         size = strlen( swlist_swname ) - ( split_2nd_loc + 1 - swlist_swname );
193         *swpart = global_alloc_array_clear(char,size+1);
193         *swpart = auto_alloc_array_clear(machine,char,size+1);
194194         memcpy( *swpart, split_2nd_loc + 1, size );
195195      }
196196      else
197197      {
198198         int size = split_1st_loc - swlist_swname;
199         *swname = global_alloc_array_clear(char,size+1);
199         *swname = auto_alloc_array_clear(machine,char,size+1);
200200         memcpy( *swname, swlist_swname, size );
201201
202202         size = strlen( swlist_swname ) - ( split_1st_loc + 1 - swlist_swname );
203         *swpart = global_alloc_array_clear(char,size+1);
203         *swpart = auto_alloc_array_clear(machine,char,size+1);
204204         memcpy( *swpart, split_1st_loc + 1, size );
205205      }
206206   }
207207   else
208208   {
209      int size = strlen( swlist_swname );
210      *swname = global_alloc_array_clear(char,size+1);
211      memcpy( *swname, swlist_swname, size );
209      *swname = auto_strdup(machine,swlist_swname);
212210   }
213211}
214212
r8128r8129
928926   *sw_part = NULL;
929927
930928   /* Split full software name into software list name and short software name */
931   software_name_split( path, &swlist_name, &swname, &swpart );
929   software_name_split( device->machine, path, &swlist_name, &swname, &swpart );
932930
933931   interface = device->get_config_string(DEVINFO_STR_INTERFACE);
934932
r8128r8129
10431041   if ( software_part_ptr )
10441042   {
10451043      /* Load the software part */
1046      load_software_part_region( device, (char *)swlist_name, (char *)software_info_ptr->shortname, software_part_ptr->romdata );
1044      try {
1045         load_software_part_region( device, (char *)swlist_name, (char *)software_info_ptr->shortname, software_part_ptr->romdata );
1046      }
1047      catch (emu_fatalerror &fatal)
1048      {
1049         software_list_close( software_list_ptr );
1050         throw fatal;
1051      }
10471052
10481053      /* Create a copy of the software and part information */
10491054      *sw_info = auto_alloc_clear( device->machine, software_info );
r8128r8129
10751080      software_info_ptr = NULL;
10761081      software_list_ptr = NULL;
10771082   }
1078   global_free( swlist_name );
1079   global_free( swname );
1080   global_free( swpart );
1083   auto_free( device->machine, swlist_name );
1084   auto_free( device->machine, swname );
1085   auto_free( device->machine, swpart );
10811086
10821087   return result;
10831088}

Previous 15994 Revisions Next


© 1998-2018 The MESS Team