Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


hmmm, could this be causing a memory leak?

This topic is 5719 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

using the sweet snippits thing from a day or so ago i messed around with this just for fun
case WM_KEYDOWN:	switch (wParam)
								case VK_SPACE:	if (Voice!=NULL)
													char *Text="Ich bin eine Nilpferd";
													WCHAR *TextBuffer=new WCHAR;
see im a lil worried about WCHAR *TextBuffer=new WCHAR; cause i mean it IS allocating a new WCHAR =/ but theres one problem if i try and delete it i get a runtime error =( and im not sure why if i do delete []TextBuffer; (or just delete TextBuffer; for that matter) i get the following error
Microsoft Visual C++ Debug Library

Debug Error!

Program: C:\Program Files\Microsoft Visual Studio\My Projects\Voice\Debug\Voice.exe

DAMAGE: after Normal block (#40) at 0x00860090.

(Press Retry to debug the application)
i KNOW it has to be caused by my deleting the TextBuffer =/ but if i dont delete it... then wont it cause a memory leak? or have i been lied to all along? lol Bungo!

Share this post

Link to post
Share on other sites
The bug is here (I think):

int MultiByteToWideChar(
UINT CodePage, // OK
DWORD dwFlags, // OK
LPCSTR lpMultiByteStr, // OK
int cchMultiByte, // OK but if this is NULL terminated string You can put -1
LPWSTR lpWideCharStr, // OK
int cchWideChar // BUG !!!!!!

You dont have allocated strlen(Text)*2 buffer for output, but only one WCHAR:
WCHAR *TextBuffer=new WCHAR;

Incres buffer size and shold be OK. i think.

Share this post

Link to post
Share on other sites

so i should do WCHAR *TexBuffer=new WCHAR[strlen(Text)*2]; ? ill try that, thanks =P (i dunno why that never occured to me, ive had to do that sooo many times before)


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!