[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Memory leaks in the C runtime library

Posted on 2001-07-16
12
Medium Priority
?
296 Views
Last Modified: 2008-02-01
I've tried to compile with VC++ under Unicode, defining UNICODE and created a simple wWinMain() function, and defined my entry point correctly. The program compiles and runs, but I get memory leaks reported by NuMega BoundsChecker from the two standard files in the C runtime library - stdargv.c and stdanvp.c, even if all I do is just return from the WinMain (i.e. there is no code in WinMain. ) The memory leaks are quite bad, totalling about 6K. Any ideas why this is?
Please post your replies to TomP@Rebellion.co.uk.
Thanks,
Tom
0
Comment
Question by:Tom_P
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 6285758
Are you using MFC then?

Did you make wWinMainCRTStartup() the entrypoint procedure in the project settings (link tab, ouput category)?
0
 

Author Comment

by:Tom_P
ID: 6285874
No, I am using straight Windows. And yes, I did specify the entry point correctly (in fact i think that the program wouldn't link otherwise. )
Any ideas would be very appreciated.
Tom
0
 

Expert Comment

by:tyronen
ID: 6288447
Does the problem occur in the release build or only the debug build?  The debug C++ runtime uses a different set of memory functions, and these may contain leaks.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Tom_P
ID: 6289172
I worked it out last night.
The problem is the following:
If (and only if) building a non-MFC application for Windows do the following:

1) #define UNICODE //not _UNICODE
2) specify WinMain as your main function (not wWinMain)
3) leave the compiler entry point set to normal (not       wWinMainCRTSStartup)

On my machine with VC++ 6.0 SP4 this builds a unicode program (i.e. all functions called are the <fnname>W's as
opposed to <fnname>A's, e.g. MessageBoxW gets called correctly, not MessageBoxA )

Thanks for your help.
Tom.
P.S. Is there any way I could give the points to myself?
0
 
LVL 22

Expert Comment

by:nietod
ID: 6289259
>> give the points to myself?
No, but you can delete the question and they will be refunded.

What you've done is create a progrma that calls unicode functions, but has an ASCII entry point.  Is that what you wanted?
0
 

Author Comment

by:Tom_P
ID: 6294466
Well not quite neitod, but it doesn't leak memory. Can you think of any reason why having an ascii entry point would cause trouble?
I am really getting tired of this. Have a look at the following piece of code:
int APIENTRY WinMain( /*params here*/)
{
 return 0;
}
0
 

Author Comment

by:Tom_P
ID: 6294497
When comiled under ANSI, no problems.
If I define _UNICODE, the versions of all the fns. called will actually be the char * versions. Which leads me to believe that _UNICODE is MFC specific.

When I define UNICODE, all fns. are wide character ones.
If I change WinMain to wWinMain and Entry point to wWinMainCRTStartup, compiles and links fine, BUT! there is a 6k memory leak in the runtime library.
When I use WinMain and normal entry point, no problems.
This is really annoying me now.
Anyway, I'd be gratefull for any ideas on this from anyone.
I use MSCV++ 6.0 with SP4, and the tool that reports memory leaks is BoundsChecker version 6.5.
Thanks, Tom
0
 
LVL 22

Expert Comment

by:nietod
ID: 6294678
>> Can you think of any reason why having an ascii entry
>> point would cause trouble?
No, but I'm only vaguely aquanted with the VC start-up code.  I've stepped through it a few times and looked at parts in detail, but I'm not thrououghly familiar with it.

>> _UNICODE is MFC specific.
yes, moistly it controls what libraries an MFC program links to and then in AFXv_w32.h it defines the vlaue of UNICODE which is the value used by windows.h.

You might try stepping through the startup-code and see where it gets lost.  Most likely it is something to do with translating the parameters to wide haracter

I wouldn't loose too much sleep over this.  (Well, actually I probably would, but I'm too compulsive too.)  This is not goin to be a steady memory leak.  i.e. it won't continue to consume memory during the program life and eventually cause a crash.  In fact, it you get it fixed, it probably won't change anything.  Most likely the memory will not be deleted until the program returns from the entry point anyways.  So it getting it delted at the program end, rather than never deleted, is not really of much value.   But I hate loose ends myself....
0
 

Author Comment

by:Tom_P
ID: 6297619
That is what I am thinking, I know (I hope) as soon as the code finishes the memory leak will be cleaned up by windows, but - I like to know what's going on. On the other hand, I have been assuming all the way that BoundChecker got it right... maybe there is a problem elsewhere..?
Anyway, thanks for all your input.
Tom
0
 
LVL 22

Expert Comment

by:nietod
ID: 6297752
>> I know (I hope) as soon as the code finishes the memory leak will be cleaned
When the program ends, the memory is returned to the OS.  There is no doubt about that.  
0
 
LVL 11

Expert Comment

by:griessh
ID: 6828308
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to refund the points and PAQ at zero points since you found your own answer.

The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 6845969
Points reduced to 0 and placed in PAQ

Thank you
E-E Moderator
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question