(do_relocs_for): Don't allocate storage or process relocs if there aren't any

relocs to process.  Avoids malloc/free bug on SCO too.
This commit is contained in:
Ken Raeburn
1993-03-23 13:34:55 +00:00
parent 214d840f9a
commit 155e7bc479

View File

@ -364,6 +364,10 @@ DEFUN (do_relocs_for, (abfd, h, file_cursor),
fixS *fix_ptr = segment_info[idx].fix_root;
nrelocs = count_entries_in_chain (idx);
if (nrelocs)
/* Bypass this stuff if no relocs. This also incidentally
avoids a SCO bug, where free(malloc(0)) tends to crash. */
{
external_reloc_size = nrelocs * RELSZ;
external_reloc_vec =
(struct external_reloc *) malloc (external_reloc_size);
@ -448,11 +452,20 @@ DEFUN (do_relocs_for, (abfd, h, file_cursor),
}
/* Write out the reloc table */
segment_info[idx].scnhdr.s_relptr = nrelocs ? *file_cursor : 0;
segment_info[idx].scnhdr.s_nreloc = nrelocs;
bfd_write ((PTR) external_reloc_vec, 1, external_reloc_size, abfd);
*file_cursor += external_reloc_size;
bfd_write ((PTR) external_reloc_vec, 1, external_reloc_size,
abfd);
free (external_reloc_vec);
/* Fill in section header info. */
segment_info[idx].scnhdr.s_relptr = *file_cursor;
*file_cursor += external_reloc_size;
}
else
{
/* No relocs */
segment_info[idx].scnhdr.s_relptr = 0;
}
segment_info[idx].scnhdr.s_nreloc = 0;
}
}
/* Set relocation_size field in file headers */