A
ashjas
Hello all..
I am experiencing memory leakes in on of my applications that i am
developing. the % of memory used for the application is increasing as
shown in the top command on linux.
The memory is leaking only when a function is called where i am
allocating memory dynamically to a pointer(char string,i,e c-string).
if i replace the logic with the use of stl string the memory leaking
problem goes off..
but i need to understand why the memory is leaking...
the overall structure is as follows..
void function()
{
char *str=new cahr[100];
///code where this string is manipulated and used....
//delete str;
}
now this function is called numerous times while the application is
running...
i know that i need to deallocate the explicit mem allocation through
free or delete...but after uncommenting the delete command the
application is aborted as soon as this function is invoked when a
specific condition is met durining application execution.
the application is aborted with the following on the command prompt:
*** glibc detected *** ./exe: munmap_chunk(): invalid pointer:
0x000000001457f85a ***
then a backtrace log is generated...
i am deleting the pointer only after its of no more use...then why is
the application being aborted saying invalid pointer...
and also after each of this function call...a newer activation frame
for the function is generated so a new pointer should exist on each
function call...
How can the memory leaking be fixed in such a scenario?
Kindly help.
I am experiencing memory leakes in on of my applications that i am
developing. the % of memory used for the application is increasing as
shown in the top command on linux.
The memory is leaking only when a function is called where i am
allocating memory dynamically to a pointer(char string,i,e c-string).
if i replace the logic with the use of stl string the memory leaking
problem goes off..
but i need to understand why the memory is leaking...
the overall structure is as follows..
void function()
{
char *str=new cahr[100];
///code where this string is manipulated and used....
//delete str;
}
now this function is called numerous times while the application is
running...
i know that i need to deallocate the explicit mem allocation through
free or delete...but after uncommenting the delete command the
application is aborted as soon as this function is invoked when a
specific condition is met durining application execution.
the application is aborted with the following on the command prompt:
*** glibc detected *** ./exe: munmap_chunk(): invalid pointer:
0x000000001457f85a ***
then a backtrace log is generated...
i am deleting the pointer only after its of no more use...then why is
the application being aborted saying invalid pointer...
and also after each of this function call...a newer activation frame
for the function is generated so a new pointer should exist on each
function call...
How can the memory leaking be fixed in such a scenario?
Kindly help.