471,049 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,049 software developers and data experts.

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

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.
Nov 17 '05 #1
0 1689

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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.