@@ -1766,10 +1766,8 @@ microblaze_elf_relax_section (bfd *abfd,
1766
1766
{
1767
1767
Elf_Internal_Shdr * symtab_hdr ;
1768
1768
Elf_Internal_Rela * internal_relocs ;
1769
- Elf_Internal_Rela * free_relocs = NULL ;
1770
1769
Elf_Internal_Rela * irel , * irelend ;
1771
1770
bfd_byte * contents = NULL ;
1772
- bfd_byte * free_contents = NULL ;
1773
1771
int rel_count ;
1774
1772
unsigned int shndx ;
1775
1773
size_t i , sym_index ;
@@ -1813,8 +1811,6 @@ microblaze_elf_relax_section (bfd *abfd,
1813
1811
internal_relocs = _bfd_elf_link_read_relocs (abfd , sec , NULL , NULL , link_info -> keep_memory );
1814
1812
if (internal_relocs == NULL )
1815
1813
goto error_return ;
1816
- if (! link_info -> keep_memory )
1817
- free_relocs = internal_relocs ;
1818
1814
1819
1815
sdata -> relax_count = 0 ;
1820
1816
sdata -> relax = (struct relax_table * ) bfd_malloc ((sec -> reloc_count + 1 )
@@ -1842,7 +1838,6 @@ microblaze_elf_relax_section (bfd *abfd,
1842
1838
contents = (bfd_byte * ) bfd_malloc (sec -> size );
1843
1839
if (contents == NULL )
1844
1840
goto error_return ;
1845
- free_contents = contents ;
1846
1841
1847
1842
if (!bfd_get_section_contents (abfd , sec , contents ,
1848
1843
(file_ptr ) 0 , sec -> size ))
@@ -2288,25 +2283,26 @@ microblaze_elf_relax_section (bfd *abfd,
2288
2283
}
2289
2284
2290
2285
elf_section_data (sec )-> relocs = internal_relocs ;
2291
- free_relocs = NULL ;
2292
2286
2293
2287
elf_section_data (sec )-> this_hdr .contents = contents ;
2294
- free_contents = NULL ;
2295
2288
2296
2289
symtab_hdr -> contents = (bfd_byte * ) isymbuf ;
2297
2290
}
2298
2291
2299
- free (free_relocs );
2300
- free_relocs = NULL ;
2292
+ if (internal_relocs != NULL
2293
+ && elf_section_data (sec )-> relocs != internal_relocs )
2294
+ free (internal_relocs );
2301
2295
2302
- if (free_contents != NULL )
2303
- {
2304
- if (!link_info -> keep_memory )
2305
- free (free_contents );
2296
+ if (contents != NULL
2297
+ && elf_section_data (sec )-> this_hdr .contents != contents )
2298
+ {
2299
+ if (! link_info -> keep_memory )
2300
+ free (contents );
2306
2301
else
2307
- /* Cache the section contents for elf_link_input_bfd. */
2308
- elf_section_data (sec )-> this_hdr .contents = contents ;
2309
- free_contents = NULL ;
2302
+ {
2303
+ /* Cache the section contents for elf_link_input_bfd. */
2304
+ elf_section_data (sec )-> this_hdr .contents = contents ;
2305
+ }
2310
2306
}
2311
2307
2312
2308
if (sdata -> relax_count == 0 )
@@ -2320,8 +2316,16 @@ microblaze_elf_relax_section (bfd *abfd,
2320
2316
return true;
2321
2317
2322
2318
error_return :
2323
- free (free_relocs );
2324
- free (free_contents );
2319
+
2320
+ if (isymbuf != NULL
2321
+ && symtab_hdr -> contents != (unsigned char * ) isymbuf )
2322
+ free (isymbuf );
2323
+ if (internal_relocs != NULL
2324
+ && elf_section_data (sec )-> relocs != internal_relocs )
2325
+ free (internal_relocs );
2326
+ if (contents != NULL
2327
+ && elf_section_data (sec )-> this_hdr .contents != contents )
2328
+ free (contents );
2325
2329
free (sdata -> relax );
2326
2330
sdata -> relax = NULL ;
2327
2331
sdata -> relax_count = 0 ;
0 commit comments