Memory leak in mfc

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hello, I'm writing an app using VS2005. I'm getting a memory leak in
the following code.

//-----------------------------
//Get the data back (16 bytes)
CString dataRead = CReader.GetData();

int i = 0;
char docArray[15];

//Take the first 14 bytes out
for(i=0; i<14; i++)
{
docArray[i] = dataRead[i];
}
docArray[14] = '\0';

//Get the value on to a CString
document = docArray;

document.Trim();

memset(docArray, 0, 0);

//-----------------------------------------

document is a CString declared in the .h file.

The leak occurs when I set:
document = docArray;

Please notice I don't do:

document = dataRead;

because I only need to get the first 14 bytes in dataRead, the last
two bytes are used for documentType.

Can anyone help me out?

Thanks.

Carlos A

.



Relevant Pages

  • Re: Memory leak in mfc
    ... Is the content of "dataRead" correct for you? ... docArray is a vector of chars. ... Could you try to use CStringA instead of CString? ... if your purpose is to extract the first N characters from dataRead ...
    (microsoft.public.vc.mfc)
  • Re: Memory leak in mfc
    ... Assigning a character array to a CString this way does not cause memory leaks. ... CString dataRead = CReader.GetData; ... document = docArray; ...
    (microsoft.public.vc.mfc)
  • Re: Memory leak in mfc
    ... Is 'document' a global CString? ... CString dataRead = CReader.GetData; ... document = docArray; ...
    (microsoft.public.vc.mfc)
  • Re: Memory leak in mfc
    ... CString dataRead = CReader.GetData; ... Why do you need a char array at all? ... Why not work directly with the CString? ... that is found in a .h file, but it would make no sense to declare a *variable* in a .h ...
    (microsoft.public.vc.mfc)
  • Memory leak
    ... I have a memory leak in one function, but I have no idea why it leaks. ... System.out.println("Error reading file: ... bytesSend += dataRead; ...
    (comp.lang.java.programmer)