468,733 Members | 1,677 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,733 developers. It's quick & easy.

malloc() causes an Access Violation when compiling with the /MT switch

Hi... I have created a utility library with VC++ 7.1 which is used by a VB 6
client. The library creates a secondary thread of execution in order to
listen for connections on a socket. The problem I am experienceing is that
the DLL works fine when it is compiled with the /MTd switch (static
Multithreaded Debug CRT) but as soon as I change it to the /MT switch
(static Multithreaded CRT), malloc() causes an Access Violation exception
after just a few calls. The exception is being raised by HeapAlloc() in
line 212 of malloc.c .

The first few calls to malloc() are allocating very small memory blocks, in
the range of 28 - 150 bytes. The call to malloc() which always raises the
exception when used with the /MT switch is trying to allocate a block of
16Kb.

When I debug the DLL with the /MTd switch, no exception occurs and there is
no assertion failures or debugging messages from the CRT or NT Heap to
indicate that there could be a problem. Also, when writing to the memory
allocated before the offending line is reached, I am very careful to not go
beyond the length of the previously allocated blocks so I'm pretty sure it
is not a buffer over-run problem.

The heap seems to be corrupting for some reason, but I can't figure out why
it only happens with the non-debug builds of the CRT.

Any help would be greatly appreciated.
Clive
Nov 17 '05 #1
0 1617

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by SCS | last post: by
3 posts views Thread by Rossel NathanaŽl | last post: by
35 posts views Thread by ytrama | last post: by
13 posts views Thread by Jean Pierre Daviau | last post: by
13 posts views Thread by ppateel | last post: by
68 posts views Thread by James Dow Allen | last post: by
10 posts views Thread by Francine.Neary | last post: by
2 posts views Thread by jthep | last post: by
39 posts views Thread by Martin | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.