J
Jason
I don't know if anyone caught my previous post about a project I've
inherited, but I have another question about it.
(Quick summary:
I have old C code, converting to C++. Compiles and runs fine)
My problem is when the application exits, CodeGuard tells me that I have
memory leaks, and points to a function.
char *fooFunc(int Bar)
{
char *returnArr = new char[8];
int stuff;
// do some stuff with Bar
sprintf(returnArr,"%2d",stuff);
return(returnArr);
}
I see that I am allocating memory, but it's not being freed. The function
is called like so:
fprintf(filePtr,"%s and stuff",fooFunc(myInt));
How do I free (delete) the memory allocated by this? I know I could change
it to
char returnArr[8];
but that would prevent me from learning anything new today.
TIA for everyone's help.
- Jason
inherited, but I have another question about it.
(Quick summary:
I have old C code, converting to C++. Compiles and runs fine)
My problem is when the application exits, CodeGuard tells me that I have
memory leaks, and points to a function.
char *fooFunc(int Bar)
{
char *returnArr = new char[8];
int stuff;
// do some stuff with Bar
sprintf(returnArr,"%2d",stuff);
return(returnArr);
}
I see that I am allocating memory, but it's not being freed. The function
is called like so:
fprintf(filePtr,"%s and stuff",fooFunc(myInt));
How do I free (delete) the memory allocated by this? I know I could change
it to
char returnArr[8];
but that would prevent me from learning anything new today.
TIA for everyone's help.
- Jason