This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: malloc overrides


2009/11/5 Yaakov (Cygwin/X):
>>> extern void _exit (int);
>>> extern char* strdup (const char*);
>>
>> Â static int are_we_stuck = 1;
>>>
>>> char* malloc(unsigned n) {
>>
>> Â Â Â are_we_stuck = 0;
>>>
>>> Â Â return 0;
>>> }
>>>
>>> int main(void) {
>>> Â Â strdup("yo");
>>
>> Â Â Â _exit (are_we_stuck);
>>>
>>> }
>>
>> Â FTFY.
>
> Funny, as I went to sleep last night I thought of just that solution. In
> practice, though, while it doesn't hang, it doesn't give the correct answer
> either. Â As Corinna said, the malloc override needs to be functional, in
> that it allocates memory which can then be free()d. ÂSo this isn't going to
> be quite so simple. :-(

Does the memory actually need to be freed?

The simplest implementation of malloc() simply advances a pointer into
an array (taking alignment into account), and the simplest
implementation of free() does nothing.

Andy

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]