Subject: bug#9273: 23.3; malloc initialization should (sometimes) happen at runtime

From: Ken Brown <[email-masked]>
Date: Thu, 11 Aug 2011 17:45:41 -0400

On 8/10/2011 11:56 AM, Eli Zaretskii wrote:
>> Date: Tue, 09 Aug 2011 16:09:48 -0400
>> From: Ken Brown<[email-masked]>
>> I made one naive attempt to do this, but it didn't work (and it was
>> Cygwin specific).  Namely, I made unexec (for Cygwin) set
>> _malloc_initialized = 0 before dumping.  The resulting emacs aborted
>> as soon as it was started.  I haven't figured out what went wrong,
>> but I'm not sure that's the right answer anyway.

The problem was that realloc got called on memory that had been 
allocated prior to dumping, and the malloc information that was used 
then had disappeared.  I think there's an obvious solution to this.  At 
the time of reinitialization, we save the previous malloc state.  Then 
if realloc is called on a pointer to something in the static heap, we 
temporarily restore the old state and let realloc proceed as it did in 
temacs prior to dumping.

Unless I've (again) missed something obvious, it shouldn't be too hard
to do this.  I'm about to go on vacation, but I should have a patch 
ready within a couple weeks.

Ken