473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

User breakpoint called from code at 0x****** when using delete operator

37
Hello
Could anybody help me?
I have the following piece of code
Expand|Select|Wrap|Line Numbers
  1.  
  2. cryptReturnVal = new BYTE[len];
  3. char *cryptReturnValueChar;
  4.  
  5. // call decrypt function            
  6. cryptReturnVal=(*decrypt)(input, len, secretKey, ecretKeySize);
  7.  
  8. // convert result in hexadecimal format
  9. cryptReturnValueChar = fromCharToHexa(cryptReturnVal, len);
  10.  
  11. m_editOutput.SetWindowText(cryptReturnValueChar);
  12.  
  13. // free memory
  14. delete [] cryptReturnVal;
  15. delete cryptReturnValueChar;
  16.  
  17.  
When i'm trying to free the dynamically allocated memory, my application crashes and i get the following message "User breakpoint called from code at 0x******". I think this means that some access violation occurs, but i don't understand why
Aug 16 '07 #1
10 8752
gpraghuram
1,275 Expert 1GB
Hello
Could anybody help me?
I have the following piece of code
Expand|Select|Wrap|Line Numbers
  1.  
  2. cryptReturnVal = new BYTE[len];//gpraghuram -- if u are allocating memory , then 
  3. char *cryptReturnValueChar;
  4.  
  5. // call decrypt function            
  6. cryptReturnVal=(*decrypt)(input, len, secretKey, ecretKeySize);//gpraghuram--the memory gets overwritten here.[/b]
  7.  
  8. // convert result in hexadecimal format
  9. cryptReturnValueChar = fromCharToHexa(cryptReturnVal, len);
  10.  
  11. m_editOutput.SetWindowText(cryptReturnValueChar);
  12.  
  13. // free memory
  14. delete [] cryptReturnVal;
  15. delete cryptReturnValueChar; // gpraghuram does the memory is allocated to this properly?
  16.  
  17.  
When i'm trying to free the dynamically allocated memory, my application crashes and i get the following message "User breakpoint called from code at 0x******". I think this means that some access violation occurs, but i don't understand why

I have some doubts in the code.....
i have put the name with comment.
This shuld be memory corruption problem, which u shuld debug to find out.

Raghuram
Aug 16 '07 #2
Dreea
37
Expand|Select|Wrap|Line Numbers
  1.  
  2. cryptReturnVal = new BYTE[len];
  3. cryptReturnValueChar=new char[2*len+1];
  4.  
  5. // call decrypt function            
  6. cryptReturnVal=(*decrypt)(input, len, secretKey, ecretKeySize);
  7.  
  8. // convert result in hexadecimal format
  9. cryptReturnValueChar = fromCharToHexa(cryptReturnVal, len);
  10.  
  11. m_editOutput.SetWindowText(cryptReturnValueChar);
  12.  
  13. // free memory
  14. delete [] cryptReturnVal;
  15. delete [] cryptReturnValueChar; 
  16.  
In order to avoid the memory being overwritten on line 5, should I comment line 1? I tryied this but the same error occurs. Thanks
Aug 16 '07 #3
gpraghuram
1,275 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1.  
  2. cryptReturnVal = new BYTE[len];
  3. cryptReturnValueChar=new char[2*len+1];
  4.  
  5. // call decrypt function            
  6. cryptReturnVal=(*decrypt)(input, len, secretKey, ecretKeySize);
  7.  
  8. // convert result in hexadecimal format
  9. cryptReturnValueChar = fromCharToHexa(cryptReturnVal, len);//This is also overwriting the memory u have allocated.
  10.  
  11. m_editOutput.SetWindowText(cryptReturnValueChar);
  12.  
  13. // free memory
  14. delete [] cryptReturnVal;
  15. delete [] cryptReturnValueChar; 
  16.  
In order to avoid the memory being overwritten on line 5, should I comment line 1? I tryied this but the same error occurs. Thanks
Try to comment out the delete one by one and find which delete is causing the issue.Then u can dig there to find the issue.
Raghuram
Aug 16 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
This doesn't work:
cryptReturnVal = new BYTE[len];
char *cryptReturnValueChar;

// call decrypt function
cryptReturnVal=(*decrypt)(input, len, secretKey, ecretKeySize);
The return from decrypt is overwriting the address obtained by new just above. Now when you delete cryptReturnVal you will crash.
Aug 16 '07 #5
Dreea
37
Try to comment out the delete one by one and find which delete is causing the issue.Then u can dig there to find the issue.
Raghuram
I already done that and i know that the problem is
Expand|Select|Wrap|Line Numbers
  1. delete [] cryptReturnVal;
  2.  
What i find odd, is the fact that the other value has no problem being deletede even though I declare it, I allocate memory for it in the same manner, it is the result of a function and then i try to delete it
Expand|Select|Wrap|Line Numbers
  1. // declare variables
  2. char *cryptReturnValueChar;
  3. BYTE *cryptReturnVal;
  4.  
  5. // allocate memory
  6. cryptReturnValueChar=new char[2*len+1];
  7. cryptReturnVal=new BYTE[len];
  8.  
  9. // call crypt function     
  10. cryptReturnVal=(*crypt)(input, len, secretKey, secretKeySize);
  11. cryptReturnValueChar = fromCharToHexa(cryptReturnVal, len);
  12.  
  13. m_edit2.SetWindowText(cryptReturnValueChar);                        
  14. // free memory
  15. delete [] cryptReturnValueChar;
  16. delete [] cryptReturnVal; // here is the problem
  17.  
I understand what you all are saying that the memory is overwritten on line 10, when the crypt function is called, but what do you sugest me to do? I tryed commenting the line in which memory is allocated with new, but this still doesn't solve my problem; i get the same "User breakpoint called from code at 0x****** " error :(
Aug 17 '07 #6
gpraghuram
1,275 Expert 1GB
I already done that and i know that the problem is
Expand|Select|Wrap|Line Numbers
  1. delete [] cryptReturnVal;
  2.  
What i find odd, is the fact that the other value has no problem being deletede even though I declare it, I allocate memory for it in the same manner, it is the result of a function and then i try to delete it
Expand|Select|Wrap|Line Numbers
  1. // declare variables
  2. char *cryptReturnValueChar;
  3. BYTE *cryptReturnVal;
  4.  
  5. // allocate memory
  6. cryptReturnValueChar=new char[2*len+1];
  7. cryptReturnVal=new BYTE[len];
  8.  
  9. // call crypt function     
  10. cryptReturnVal=(*crypt)(input, len, secretKey, secretKeySize);
  11. cryptReturnValueChar = fromCharToHexa(cryptReturnVal, len);
  12.  
  13. m_edit2.SetWindowText(cryptReturnValueChar);                        
  14. // free memory
  15. delete [] cryptReturnValueChar;
  16. delete [] cryptReturnVal; // here is the problem
  17.  
I understand what you all are saying that the memory is overwritten on line 10, when the crypt function is called, but what do you sugest me to do? I tryed commenting the line in which memory is allocated with new, but this still doesn't solve my problem; i get the same "User breakpoint called from code at 0x****** when using delete operator" error :(
Hi,
1)first check what the function pointer call return.
2)Then u can deceide whether u can delete the memory or not.

Raghuram
Aug 17 '07 #7
Dreea
37
Hi,
1)first check what the function pointer call return.
2)Then u can deceide whether u can delete the memory or not.

Raghuram
Expand|Select|Wrap|Line Numbers
  1. typedef BYTE* (*DLLCRYPT) (BYTE*, UINT, BYTE*, UINT);
  2. DLLCRYPT crypt;
  3. ..............................
  4. crypt = (DLLCRYPT) GetProcAddress(hinstDLL, "crypt");
  5. .................................................................................
  6. cryptReturnVal=(*crypt)(input, len, secretKey, secretKeySize);
  7.  
Aug 17 '07 #8
gpraghuram
1,275 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. typedef BYTE* (*DLLCRYPT) (BYTE*, UINT, BYTE*, UINT);
  2. DLLCRYPT crypt;
  3. ..............................
  4. crypt = (DLLCRYPT) GetProcAddress(hinstDLL, "crypt");
  5. .................................................................................
  6. cryptReturnVal=(*crypt)(input, len, secretKey, secretKeySize);
  7.  
Hi,
As it is returning a process address, i am very sure that u cant delete the memory.
If u have a memory-corruption identification tool u can use it.
Try Rational-Purify

Raghuram
Aug 17 '07 #9
LRESULT CWnd::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// OnWndMsg does most of the work, except for DefWindowProc call
LRESULT lResult = 0;
if (!OnWndMsg(message, wParam, lParam, &lResult))
lResult = DefWindowProc(message, wParam, lParam);
return lResult;
}

I get a 'User breakpoint called from code at *******' error.

The lResult and the lparam values are both at zero. I am clueless as to how to proceed and will be grateful of any help I can receive.

This is not the only place where I get a 'user breakpoint' in debug mode. I get the same here too:

#ifndef _AFX_NO_DEBUG_CRT
// we remove WM_QUIT because if it is in the queue then the message box
// won't display
MSG msg;
BOOL bQuit = PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE);
BOOL bResult = _CrtDbgReport(_CRT_ASSERT, lpszFileName, nLine, NULL, NULL);
if (bQuit)
PostQuitMessage(msg.wParam);
return bResult;

The bQuit value stands at 0 here.
Help.
Dec 2 '08 #10
gpraghuram
1,275 Expert 1GB
It would be better if you create a new thread.
If u are using windows then try heapchk() which will give the heap status.
Introduce this befor and after every function call and find oout where the memory is getting corrupted.


Raghu
Dec 3 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tobias Langner | last post by:
I overloaded the operator= - but in the program, if the line p3=p1 gets executed, the program doesn't jump to the method. The class definition and the test code. template <class T, template...
3
by: Tron Thomas | last post by:
Given the following code: #include <vector> #include <algorithm> #include <functional> class Value { public: explicit Value(int value) : m_value(value) {}
4
by: Aaron Queenan | last post by:
When I build a C++ library to .NET using the managed C++ compiler, I get the following error message: Linking... LINK : error LNK2020: unresolved token (0A000005) _CrtDbgReport LINK : error...
2
by: Michael Ramey | last post by:
Howdy, I think I have a good question! I'm creating a usercontrol, and within this usercontrol, I'm dynamically creating controls (imagebuttons to be exact), that the user can click on which...
1
by: Kris van der Mast | last post by:
Hi, been a while since I posted a question myself instead of trying to help others out. I'm refactoring an existing web app that uses dynamic loading of user controls and a lot of...
8
by: Razak | last post by:
Hi, I have a class which basically do Impersonation in my web application. From MS KB sample:- ++++++++++++++++++++code starts Dim impersonationContext As...
9
by: David | last post by:
Hi all, I posted my question two days ago, and tried to solve this problem. but until now I didn't solve that. and I cut my codes so maybe this time it is more readable. ...
10
by: jeffjohnson_alpha | last post by:
We all know that a new-expression, foo* a = new foo() ; allocates memory for a single foo then calls foo::foo(). And we know that void* p = ::operator new(sizeof(foo)) ; allocates a...
4
by: mail.dsp | last post by:
Suppose in a class we overload four operators: operator new operator delete operator new operator delete class Test{ public: void * operator new (size_t t){ cout<<"\nCalling... new";
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.