move up call stack one level
-
I am writing code to track down memory leaks in our program. I am doing this by overloading the new(size_t), new[](size_t), delete(size_t) and delete[](size_t) functions so that I can keep track of which calls to new do not have a corresponding delete. This is all working well. Now to my question, try as I might I cannot get the callers __FILE__ and __LINE__ information which I also need. I have tried #define new new(__FILE__,__LINE__) etc... but this is not compatible with existing code. I therefore feel that at some point in the call to new and new[], etc... that I need to move up the call stack a level to the caller so as I can obtain the __FILE__ and __LINE__ information from the stack page of interest. Does anyone have any example code of how this can be done, please?
-
I am writing code to track down memory leaks in our program. I am doing this by overloading the new(size_t), new[](size_t), delete(size_t) and delete[](size_t) functions so that I can keep track of which calls to new do not have a corresponding delete. This is all working well. Now to my question, try as I might I cannot get the callers __FILE__ and __LINE__ information which I also need. I have tried #define new new(__FILE__,__LINE__) etc... but this is not compatible with existing code. I therefore feel that at some point in the call to new and new[], etc... that I need to move up the call stack a level to the caller so as I can obtain the __FILE__ and __LINE__ information from the stack page of interest. Does anyone have any example code of how this can be done, please?
Andy H wrote:
I have tried #define new new(__FILE__,__LINE__) etc... but this is not compatible with existing code.
Just for my own edification, why not?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
I am writing code to track down memory leaks in our program. I am doing this by overloading the new(size_t), new[](size_t), delete(size_t) and delete[](size_t) functions so that I can keep track of which calls to new do not have a corresponding delete. This is all working well. Now to my question, try as I might I cannot get the callers __FILE__ and __LINE__ information which I also need. I have tried #define new new(__FILE__,__LINE__) etc... but this is not compatible with existing code. I therefore feel that at some point in the call to new and new[], etc... that I need to move up the call stack a level to the caller so as I can obtain the __FILE__ and __LINE__ information from the stack page of interest. Does anyone have any example code of how this can be done, please?
-
I am writing code to track down memory leaks in our program. I am doing this by overloading the new(size_t), new[](size_t), delete(size_t) and delete[](size_t) functions so that I can keep track of which calls to new do not have a corresponding delete. This is all working well. Now to my question, try as I might I cannot get the callers __FILE__ and __LINE__ information which I also need. I have tried #define new new(__FILE__,__LINE__) etc... but this is not compatible with existing code. I therefore feel that at some point in the call to new and new[], etc... that I need to move up the call stack a level to the caller so as I can obtain the __FILE__ and __LINE__ information from the stack page of interest. Does anyone have any example code of how this can be done, please?
-
I don't get, how do you want to get file and line with stack trace, but you can obtain your return address with
void *lpReturnAddress; __asm { mov lpReturnAddress, DWORD PTR[esp] }