Home > Software engineering >  Is this the cause of the error please
Is this the cause of the error please

Time:10-11


Afx_msg long MyDlg: : OnRecvData (WPARAM WPARAM, LPARAM LPARAM)

{

Cstrings strRecv=L "";

//a serial port receives the BUF

WParam BYTE * pbufs=(BYTE *);

//a serial port receives the BUF length

DWORD dwBufLen=lParam;

Cstrings temp.

for(int i=0; i
{

Temp. The Format (" % L 02 x ", pbufs [I]);

StrRecv +=temp;

}



//add new receives the text to the receiving box

M_table. InsertItem (0, strRecv);



//release the memory

The delete [] pbufs;

Pbufs=NULL;

return 0;

}

CodePudding user response:

Pbufs did not apply for new space, so finally do not need to be released

CodePudding user response:

http://blog.csdn.net/echojiangyq_fight/article/details/18045867

CodePudding user response:

Basically see
WParam BYTE * pbufs=(BYTE *);
The origin of the wParam, if is another place in the new, and to delete here, the code is right, if it is not new, or is deleted in other places, have a problem that the code, the last of the
The delete [] pbufs;
Pbufs=NULL;
Two lines do not

CodePudding user response:

Principle: adhere to who create, who released
Pbufs finally don't need to delete [];
Look (BYTE *) wParam is how to, and again there for memory management,
  • Related