Tech Support > Microsoft Windows > Development Resources > malloc()
malloc()
Posted by Kip Warner on January 22nd, 2004


Hey guys,

Is there any way I could deny a process malloc() (and win32 counterpart)
operations? That is, return NULL.

Kip

Posted by Tim Robinson on January 22nd, 2004


"Kip Warner" <Kip@NOSPAMTheVertigo.com> wrote in message
news:40102F34.CC957520@NOSPAMTheVertigo.com...
A few more details, maybe?

If you have the source code to the application you're interested in:

---- some_header.h
#define malloc my_malloc

---- some_source.cpp
void *my_malloc(size_t bytes)
{
if (should_return_null)
return NULL;
else
return malloc(bytes);
}
----

If you want to truly catch all allocation functions, you could hook them
using Detours.

Why do you want to do this?

--
Tim Robinson (MVP, Windows SDK)
http://www.themobius.co.uk/



Posted by Kip Warner on January 23rd, 2004


Tim Robinson wrote:
Basically, I want to be able to remotely shut off malloc() calls in
another application from inside my tool. That is, find out how well they
behave while under fire.

Kip

Posted by Stephen Kellett on January 23rd, 2004


In message <40107A22.F61322BF@NOSPAMTheVertigo.com>, Kip Warner
<Kip@NOSPAMTheVertigo.com> writes
You are writing a stress testing tool?

Hook them using Detours or BugSlayer's HookImportedFunctionByName().
Not knowing anything about Detours (as we have our own equivalent here
and Detours is banned for commercial use) I can't comment on that.
BugSlayer's HookImportedFunctionByName() is straightforward to use.

Search for John Robbins and/or BugSlayer and you'll find the hooking
code. Alternatively code project http://www.codeproject.com has some
very comprehensive articles on hooking.

Shouldn't take long to do what you want.

Regards

Stephen
--
Stephen Kellett
Object Media Limited http://www.objmedia.demon.co.uk
RSI Information: http://www.objmedia.demon.co.uk/rsi.html

Posted by Kip Warner on January 23rd, 2004


Stephen Kellett wrote:
I guess stress testing tool is the name for it. Thanks man. I will let
you know how it progresses.

Kip

Posted by Stephen Kellett on January 23rd, 2004


In message <40117E8B.CBB7DA9@NOSPAMTheVertigo.com>, Kip Warner
<Kip@NOSPAMTheVertigo.com> writes
What exactly is the tool going to do?
--
Stephen Kellett
Object Media Limited http://www.objmedia.demon.co.uk
RSI Information: http://www.objmedia.demon.co.uk/rsi.html

Posted by Dim St Thomas on January 25th, 2004


Kip Warner <Kip@NOSPAMTheVertigo.com> wrote in message news:<40107A22.F61322BF@NOSPAMTheVertigo.com>...
Isn't that a bit like testing cars for safety by pushing them off a
cliff?

It is reasonable to expect applications to check the return value from
malloc and catch bad_alloc exceptions thrown by new if they are
allocating large chunks of memory. Do you expect all programs to
handle any failure of malloc gracefully and how would you suggest they
do this? Note that when you get to the point where a malloc of a small
amount of memory fails, calling something like MessageBox will also
fail due to lack of memory. Also the user would have received warnings
about system memory running low long before this point was reached.

Posted by Kip Warner on January 25th, 2004


Dim St Thomas wrote:
I don't care much for other software, I just want to test how well my
code works for this. You are probably right about malloc(), but the
thing is, it is probability that you are talking about. But I am not
concerned with things go as planned =)

Kip

Posted by Kip Warner on January 25th, 2004


Stephen Kellett wrote:
It will just deny malloc() requests by returning NULL to whatever
process I choose.

Kip


Similar Posts