Debug Assertion Failed #3

I have the following code in my thread:

while (true)
{
    FData * pData = new FData();
    .....
    .....
    .....
    if (something==true)
    {
         Sleep(1000);
         delete pData ;
         continue;
     }
}

i get Debug Assertion Failed because of the delete pData. Why?


Regards,
Mystique


0
misic (56)
2/2/2006 1:50:33 PM
vc.mfc 33608 articles. 0 followers. Follow

11 Replies
622 Views

Similar Articles

[PageSpeed] 56

Assuming pData is properly allocated, deleting should not cause the
assert. You dont show the line of code where the assert is coming from.
Are you using pData after it has been deleted?

-----
Ajay Kalra
ajaykalra@yahoo.com

0
ajaykalra (6841)
2/2/2006 1:55:28 PM
Mystique wrote:
> i get Debug Assertion Failed because of the delete pData. Why?

You have most likely wrought over the boundaries of the buffer pointed 
to by pData. Boundaries are designated with so called "no man's land", 
four bytes 0xFDFDFDFD. Find them right after the buffer is created, an 
then verify that they are (un)changed right before the buffer is to be 
deleted. Note: four bytes right before and right after the buffer.
0
mac1 (347)
2/2/2006 2:46:49 PM
yes i am, but the continue statement should bring the execution back to the
begining of the while loop

"Ajay Kalra" <ajaykalra@yahoo.com> wrote in message
news:1138888528.625853.291750@z14g2000cwz.googlegroups.com...
> Assuming pData is properly allocated, deleting should not cause the
> assert. You dont show the line of code where the assert is coming from.
> Are you using pData after it has been deleted?
>
> -----
> Ajay Kalra
> ajaykalra@yahoo.com
>


0
misic (56)
2/2/2006 2:48:01 PM
"Mystique" <misic@softhome.net> wrote in message 
news:%233%235I7$JGHA.2012@TK2MSFTNGP14.phx.gbl...
>I have the following code in my thread:
>
> while (true)
> {
>    FData * pData = new FData();
>    .....
>    .....
>    .....
>    if (something==true)
>    {
>         Sleep(1000);
>         delete pData ;
>         continue;
>     }
> }
>
> i get Debug Assertion Failed because of the delete pData. Why?
>
>
> Regards,
> Mystique
>
>

Probably you overwrite somewhere your pData (stack overrun) and it contains 
wrong address. Check the value of pData when you allocate it and when you 
delete it, if it differs, then your code overwrites it.

--
Vladimir 


0
2/2/2006 3:11:07 PM
just put the complete code instead of "..."

-- 
Vipin Aravind

"Mystique" <misic@softhome.net> wrote in message 
news:uAt7PbAKGHA.720@TK2MSFTNGP14.phx.gbl...
> yes i am, but the continue statement should bring the execution back to 
> the
> begining of the while loop
>
> "Ajay Kalra" <ajaykalra@yahoo.com> wrote in message
> news:1138888528.625853.291750@z14g2000cwz.googlegroups.com...
>> Assuming pData is properly allocated, deleting should not cause the
>> assert. You dont show the line of code where the assert is coming from.
>> Are you using pData after it has been deleted?
>>
>> -----
>> Ajay Kalra
>> ajaykalra@yahoo.com
>>
>
> 


0
vipin (697)
2/2/2006 3:30:01 PM
bool CMyDlg::test()

{

while (true)

{

FData * pData = new FData();

MyKeeper aKeeper(pData);

Sort(aKeeper);

if (pData->id() == 0)

{

Sleep(1000);

delete pData;

continue;

}

if (pData->ID() != 5)

{

pData->SetName("eeee");

}

}

return TRUE;

}

i checked the address when pData is created and when it is being deleted an
it is the same.

"Vipin [MVP]" <Vipin@nospam.com> wrote in message
news:u31mI2AKGHA.3960@TK2MSFTNGP09.phx.gbl...
> just put the complete code instead of "..."
>
> --
> Vipin Aravind
>
> "Mystique" <misic@softhome.net> wrote in message
> news:uAt7PbAKGHA.720@TK2MSFTNGP14.phx.gbl...
> > yes i am, but the continue statement should bring the execution back to
> > the
> > begining of the while loop
> >
> > "Ajay Kalra" <ajaykalra@yahoo.com> wrote in message
> > news:1138888528.625853.291750@z14g2000cwz.googlegroups.com...
> >> Assuming pData is properly allocated, deleting should not cause the
> >> assert. You dont show the line of code where the assert is coming from.
> >> Are you using pData after it has been deleted?
> >>
> >> -----
> >> Ajay Kalra
> >> ajaykalra@yahoo.com
> >>
> >
> >
>
>


0
misic (56)
2/2/2006 3:51:03 PM
What do these two statements do over there, post that code also
( I meant the cosntructor and the Sort function)

MyKeeper aKeeper(pData);
Sort(aKeeper);


-- 
Vipin Aravind

"Mystique" <misic@softhome.net> wrote in message 
news:OBHce%23AKGHA.216@TK2MSFTNGP15.phx.gbl...
> bool CMyDlg::test()
>
> {
>
> while (true)
>
> {
>
> FData * pData = new FData();
>
> MyKeeper aKeeper(pData);
>
> Sort(aKeeper);
>
> if (pData->id() == 0)
>
> {
>
> Sleep(1000);
>
> delete pData;
>
> continue;
>
> }
>
> if (pData->ID() != 5)
>
> {
>
> pData->SetName("eeee");
>
> }
>
> }
>
> return TRUE;
>
> }
>
> i checked the address when pData is created and when it is being deleted 
> an
> it is the same.
>
> "Vipin [MVP]" <Vipin@nospam.com> wrote in message
> news:u31mI2AKGHA.3960@TK2MSFTNGP09.phx.gbl...
>> just put the complete code instead of "..."
>>
>> --
>> Vipin Aravind
>>
>> "Mystique" <misic@softhome.net> wrote in message
>> news:uAt7PbAKGHA.720@TK2MSFTNGP14.phx.gbl...
>> > yes i am, but the continue statement should bring the execution back to
>> > the
>> > begining of the while loop
>> >
>> > "Ajay Kalra" <ajaykalra@yahoo.com> wrote in message
>> > news:1138888528.625853.291750@z14g2000cwz.googlegroups.com...
>> >> Assuming pData is properly allocated, deleting should not cause the
>> >> assert. You dont show the line of code where the assert is coming 
>> >> from.
>> >> Are you using pData after it has been deleted?
>> >>
>> >> -----
>> >> Ajay Kalra
>> >> ajaykalra@yahoo.com
>> >>
>> >
>> >
>>
>>
>
> 


0
vipin (697)
2/2/2006 3:53:42 PM
"Mystique" <misic@softhome.net> wrote in message
news:OBHce#AKGHA.216@TK2MSFTNGP15.phx.gbl...
> bool CMyDlg::test()
>
> {
>
> while (true)
>
> {
>
> FData * pData = new FData();
>
> MyKeeper aKeeper(pData);
>
> Sort(aKeeper);
>
> if (pData->id() == 0)
>
> {
>
> Sleep(1000);
>
> delete pData;
>
> continue;
>
> }
>
> if (pData->ID() != 5)
>
> {
>
> pData->SetName("eeee");
>
> }
>
> }
>
> return TRUE;
>
> }
>
> i checked the address when pData is created and when it is being deleted
an
> it is the same.

Well, you don't tell us what MyKeeper does, but you're deleting something it
points to without telling it that its pointer is being invalidated, which
doesn't seem like good news. And if pData->id() isn't zero you're leaking an
FData every time round the loop ... unless of course the MyKeeper destructor
deletes it, in which case you're deleting it twice so no wonder something
falls over, aren't you lucky it fell over within a few lines of the error
rather than a couple of billion instructions later as usually happens in
real life (in the release build only).

--
Tim Ward
Brett Ward Limited - www.brettward.co.uk


0
tw2 (223)
2/2/2006 3:58:48 PM
> What do these two statements do over there, post that code also
> ( I meant the cosntructor and the Sort function)
>
> MyKeeper aKeeper(pData);
> Sort(aKeeper);

Nah, we probably don't care what the *con*structor does, it's the
*de*structor that's likely to be interesting!

--
Tim Ward
Brett Ward Limited - www.brettward.co.uk


0
tw2 (223)
2/2/2006 4:00:05 PM
As pointed out,  this is not good code. You are probably getting errors
when aKeeper goes out of scope. Its hanging on to pData which is no
longer valid. Perhaps its deleting it in its destructor thats causing
the problem or maybe its simply dereferencing pData in its destructor.

-------
Ajay Kalra
ajaykalra@yahoo.com

0
ajaykalra (6841)
2/2/2006 4:04:26 PM
That's what I am trying to figure out.
Is the constructor making a copy of the pData?

-- 
Vipin Aravind

"Tim Ward" <tw2@ipaccess.com> wrote in message 
news:44eok6F1qc1dU1@individual.net...
>> What do these two statements do over there, post that code also
>> ( I meant the cosntructor and the Sort function)
>>
>> MyKeeper aKeeper(pData);
>> Sort(aKeeper);
>
> Nah, we probably don't care what the *con*structor does, it's the
> *de*structor that's likely to be interesting!
>
> --
> Tim Ward
> Brett Ward Limited - www.brettward.co.uk
>
> 


0
vipin (697)
2/2/2006 4:10:05 PM
Reply:

Similar Artilces:

Print preview problem... #3
Hi! I'm writting an MDI-project using MFC in a statically linked library. View class is derived from CListView. I've added printing functions and didn't edit them. The problem is that choosing menu Print Preview asserts the progam... When using MFC in a shared dll, program works perfectly. But I want it to work on another computers... How can I fix this problem? -- Tim. -- Tim. ...

3.0 Upgrade Failed
We have recently been trying to upgrade our 1.2 installation to 3.0, but have ran into some stumbling blocks along the way. After resolving the "Invalid SQL replication data" error on the advisor we were finally able to continue on with the installation but now continuously get the below error causing a failed installation. The enviornment is as such: SQL 2000 SP4 on 2003 std CRM 1.2 on seperate 2003 std Active Directory operating in 2003 functional Any thoughts or suggestions are welcome. Thanks! Error| Install exception.System.Exception: Action Microsoft.Crm.Setup.Server....

RUS #3
We have migrated most of our mailboxes from 5.5 to 2003 cluster and had the RUS service pointed to our 5.5 server. When should this be pointed to the virtual Exchange server? This needs to be pointed to a 2000 or 2003 server that isn't a Front-End. -- Hope that helps, Dan Townsend This posting is provided "AS IS" with no warranties, and confers no rights. Please do not send email to this address, post a reply to this newsgroup. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm "Joe Black" <anonym...

PowerShell ISE requires .NET 3.5.1 or 3.0?
Can anyone clear this up for me? I thought PowerShell ISE required .NET 3.5.1, but have managed to install it on Windows Server 2008 with only .NET 3.0 installed. See this for more detailed info: http://www.jonathanmedd.net/2009/12/powershell-ise-on-windows-server-2008-what-version-of-net-is-required.html Thanks Don't worry. Aleksandar helpfully pointed out that the answer is in about_Windows_PowerShell_ISE in PowerShell help. System Requirements – Microsoft .NET Framework 3.0 "jmedd" wrote: > Can anyone clear this up for me? I thought PowerShell I...

Dialog and asserts
Hi, I have a dialog based application and I want to open another dialog. I have a function int CMyDialog::Execute { // CMyDialog::Execute int ret_code; CNewDialog m_NewDialog(this); ret_code = m_NewDialog.DoModal(); return ret_code; } // CMyDialog::Execute that opens this dialog but this fail :( I got at assert on this line BOOL CWnd::Attach(HWND hWndNew) { ---> ASSERT(m_hWnd == NULL); // only attach once, detach on I have realized my application with the Wizard so I am not very expert about this stuff. Can someone tell me what's happening ? Stefano Malavasi __...

The Operation on the | Object failed
I have an access database linked to a SQL server 2005 back end database and my users randomly get the above message on occasions. It appears to usually happen when running VBA code. Can anybody help? ...

Update Fails to Load
I have tried several times to install KB979683 and keep getting failure message. All other updates load fine. Also, have Stopzilla and McAfee Virus Scan but can't seem to get rid of a malicious file that won't let me go to sites when I look up things on google, bing....always get sent to advertisement websites. Any ideas or helpful suggestions!! Thanks Always state your full Windows version (e.g., WinXP SP3; WinXP 64-bit SP2; Vista SP1; Vista 64-bit SP2; Win7; Win7 64-bit) when posting in a forum or newsgroup. Please do so in your next reply. When does your McAfee su...

ANN: nxslt (.NET XSLT Command Line Utility) version 1.3
Hello! I'm glad to announce version 1.3 of nxslt - .NET XSLT command line utility. What is nxslt nxslt is a feature-rich command line utility that allows to perform XSL Transformations (XSLT) using .NET Framework's XSLT implementation - System.Xml.Xsl.XslTransform class. nxslt basically dublicates functionality and command line options, provided by Microsoft's MSXSL.EXE Command Line Transformation Utility. In addition, nxslt has some distinct advanced features, like support for XInclude, embedded stylesheets, custom URI resolving, multiple result documents, custom extension fun...

Unable to download templates_says server is down_for 3 days?
Unable to download Microsoft templates!!! For days! Please help -- SherBear412004 ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/office/community/en-us/default.mspx?mid=d4d14ea5-53dd-4c0f-971c-6d4d71884450&dg=microsoft.public.excel.misc ...

Debug Assertion Faild
Debug Assertion Fail Program: C:..... File: winocc.cp Line: 22 The exception Breakpoin A breakpoint has been reache (0x80000003) occurred in the application at location 0x5f4369c This program is to scan a file and look for a matching string. Could this error be caused by code not exiting a "break;" properly? I'm not sure how to explore resolving this. The information listed in the Debug is The thread 0x3DD8 has exited with code 0 (0x0) The thread 0x3EA8 has exited with code -2147483645 (0x80000003) The program 'C:\Documents and Settings\Owner\My Documents\Dads\Programmi...

Date Format #3
How do you change the date format (ie. day-month-year to month-day-year) in Money? Money uses the Windows Regional Settings for the date format. You can find this in the Control Panel. "Philip" <ricoandcj@coxt.net> wrote in message news:043701c3899e$ac43d2f0$a001280a@phx.gbl... > How do you change the date format (ie. day-month-year to > month-day-year) in Money? Control Panel > Regional settings -- Regards Bob Peel, Microsoft MVP - Money Hints/Tips http://support.microsoft.com/default.aspx?scid=fh;EN-GB;mny UK Wishes/Suggestions mnyukwsh@mic...

SFO 3.0 on workgroup computers
Hi. We have done a couple of SFO install on worksgroup computers. Everything works fine. The users connect to the domain via ISA VPN. The users username and password is the same on the workgroup computer and in the domain. Now we get this error when we install on som new workgroup computers. Is is not posible to install the SFO on worksgroup computers? Best regards Jacob Mondrup Vivant IT Management Microsoft CRM Setup Is Being Run By a User Who Is Not a Domain User Cause Microsoft CRM Setup is being run by a user who is not a domain user. Solution Exit Microsoft CRM Setup and log on ...

Importing Address Book #3
Happy New Year to all you hard working people down there. I've tried to import my Outlook Express Address book into Outlook 2000. No matter what form I try to import with it fails. Can this be done? If so, How. File > Import and Export > Internet Mail and Addresses -- Russ Valentine [MVP-Outlook] "Rudy de Vries" <anonymous@discussions.microsoft.com> wrote in message news:007801c3d0a4$43fd8d10$a501280a@phx.gbl... > Happy New Year to all you hard working people down there. > > I've tried to import my Outlook Express Address book into > Outlook 20...

How to reinstall failed updates in Windows 7
How do i try to reinstall failed updates ? Seems windows update doesn't support that. I have Windows 7. Suggest you post this to the Windows 7 forum instead of the * Windows Update * newsgroup: http://social.answers.microsoft.com/Forums/en-US/w7install/threads "JamesW" wrote: > How do i try to reinstall failed updates ? > > Seems windows update doesn't support that. > > I have Windows 7. Ditto - another Win7 user here - when I follow recommendation to troubleshoot on the error code "WindowsUpdate_8020000E" appears as non...

Re: delete row based on conditions #3
Hello Bob, I am not getting the required result by using the formula provided by you. Trigger is Pos NO. The basic Position NOs are like e.g 2500 25000 100 200 2000 etc. in addition to this we have position number like 2591 25091 191 291 2091 etc If in an assembly Pos nos like e.g 2500 & 2591 exists delete row containing Pos.2500 25000 & 25091 exists delete row containing Pos. 25000 100 & 191 exists delete row containing Pos. 100 Hope i have explained properly Regards, Jimmy What exactly is the rule here Jimmy? Do you want to delete all rows that are not a multiple...

OWA Fails to Load
Two OWA environments are failing with the same behavior. 1) The first environment is Windows NT 4 SP6a running Exchange 5.5 SP4. OWA is hosted on seperate NT box running IIS. IIS box must be restarted to temporarilly solve problem. Works for a day or so then main OWA page fails to talk to Exchange box after login and simply hangs with no erors, or gives an ASP error, but nothing in eventlogs. Cannot restart WWW service on IIS box. 2) Second environment is Windows 2000 SP4 running Exchange 5.5 SP4 and IIS on the same box. Same behavior as first environment. OWA hangs after login and does...

DEBUG
Curious, new problem has started. Evey once in a whle a new folder appears on my desktop labeled "debug"..The folder is empty and I do not know how it is formed or why..Does someone know the cause of this and a remedy so it does not appear again Thanks Running Xp professtional heshie wrote: > Curious, new problem has started. Evey once in a whle a new folder appears on > my desktop labeled "debug"..The folder is empty and I do not know how it is > formed or why..Does someone know the cause of this and a remedy so it does > not appear again &g...

When the VBA Project is locked the Save As Method fails in Excel
I cannot find a resolution. I already have the VB Code secure (the VBA Project is locked). When the Project is locked the Save As Method fails. If the VBA Project is not locked, the Save As Method works successfully. I cannot seem to find anything that addresses that situation. Do I need to get a digital signature? Do you think that will fix the problem? ...

An application crashes only under debugging
Hi, I'm using VC++ 6.0. I have a Win32 Application (I will call it "EXE") which is linked with a Win32 DLL and I don't have the source files of the DLL; When I execute the EXE by double-clicking on the icon reprsenting it , there are no problems; On the contrary, if I try to debug the EXE the program crashes: in fact, the debugger shows an "Access Violation" error message and informs that an istruction of the DLL attempts to read a memory location which cannot be read. Does someone know a possible cause of this problem? Thanks. M If the DLL is an MFC DLL (it is...

Macro Button #3
I need to change the background color of a button created to execute a macro and change the word wrap property to true so all of the text can be viewed on the button. Any advise is much appreciated. Thanks Hi Maggie, Assuming that the button is from the Controls Toolbox, Right-click the button | Properties Double-click the 'BackColor' option | Palette and select a color Double-click the 'WordWrap' option (to select True) Close the Properties window --- Regards, Norman "Maggie" <Maggie@discussions.microsoft.com> wrote in message news:5AAF09DB-3BFB-400...

Microsoft Home & Student 2007....3 User Copy
I had Home & Student 2007 installed on a PC that suddenly stopped running; the Hard Drive failed. Rather than pay to fix it, I purchased a new PC. When I tried to Install Home & Student 2007 on my New PC...I got the message I had already had this software installed on 3 PC's. How can I install this software on my New PC? "denmarfl" <denmarfl@discussions.microsoft.com> wrote in message news:C993CFB9-19FD-485C-AAEC-9BF3A3DB59A6@microsoft.com... > I had Home & Student 2007 installed on a PC that suddenly stopped running; > the Hard Drive ...

Portfolio Manger Fails
I see where others have a similar problem, but have read no solution. After "upgrading" from Money2004 to Money2005, the portfolio manager pages shows a blank screen. No investment information whatsoever. Any ideas on a work around.... In microsoft.public.money, brawn wrote: >I see where others have a similar problem, but have read no solution. After >"upgrading" from Money2004 to Money2005, the portfolio manager pages shows a >blank screen. No investment information whatsoever. Any ideas on a work >around.... Does Help->About show version 14.0...

Weird: CRichEditCtrl scrollbars work in debug build but not in release build
Hi, I have an App Wizard project (VS 6.0), non doc-view architecture. My view class is: class CRichTextView : public CRichEditCtrl. In MainFrm.cpp I have a member variable of: CRichTextView m_wndView;. I create the view as follows: if (!m_wndView.Create(WS_CHILD | WS_VISIBLE | ES_AUTOVSCROLL | ES_MULTILINE | WS_VSCROLL, CRect(0,0,0,0), this, AFX_IDW_PANE_FIRST)) { TRACE0("Failed to create view window\n"); return -1; } It works "just peachy" in the debug build. But, when I make...

Authentication failed because Entourage doesn't support any of the available authentication methods. 04-13-10
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Email Client: pop Out of a sudden, i can't send out email and received the above error message. <br><br>For incoming email, i've no problem receiving. <br><br>I've not done any changes in my email account setting. <br><br>Anyone encountered the same problem? Please assist and advice. <br><br>Thanks ...

file not found #3
When I open an excel file in excel 2000, I get the message file not found. I click cancel about 8 times to finally get in my file. I thought maybe I had a stray cell reference to a file that didn't exist, but I can't find any obscure cell references. When I open the file in excel 2002 at home, I do not get this error message. It is driving me crazy because everytime I open this file at work I have to click cancel so many times. Any chance there's any code in the workbook referencing another file, or buttons assigned macros in another workbook? Nikos >-----Original...