帮忙看下这段代码那里内存泄漏

来源:百度知道 编辑:UC知道 时间:2024/09/23 03:55:26
void CDeviceManageDlg::LoadPictureFromDatabase(int jpgID)
{
if (!bAccessFlag) {
AfxMessageBox("请确定数据库连接是否成功!");
return;
}
//从数据库里取JPG图像文件
try
{
_RecordsetPtr pRecordset;
char sSql[129];
sprintf(sSql,"SELECT *FROM LingJian WHERE 编号=%ld",jpgID);
pRecordset.CreateInstance(__uuidof(Recordset));
pRecordset->Open(sSql,_variant_t((IDispatch*)m_pConnection),adOpenStatic,adLockOptimistic,adCmdText);
if (pRecordset->adoEOF)
{
CString str;
str="出错";
AfxMessageBox(str);
Invalidate();
return;
}
_variant_t pvList ;
long lDataSize = pRecordset->GetFields()->GetItem("TuPian")->ActualSize;
m_nFileLen = (DWORD)lDataSize;
if(lDataSize > 0)
{
_variant_t varBLOB;
varBLOB = pRecordset->GetFields()->GetItem("TuPian")->GetChunk(lDataSize

不是很确定,你试试吧。
1. if (pRecordset->adoEOF)
{
CString str;
str="出错";
AfxMessageBox(str);
Invalidate();
return;
}
这里pRecordset没有close

2. 两层try{}catch{}:
try{}中开辟的内存空间,有可能会因为跑进catch{}而没被释放。

没有内存泄露了吧,
m_pJPGBuffer = new char[lDataSize+1]
这里使用了new
下面配套有:delete[] m_pJPGBuffer;

hMem使用了GlobalAlloc,配套的使用了GlobalFree

其他没有动态分配内存的部分了,所以没有内存泄露了。


m_pJPGBuffer = new char[lDataSize+1]
这里使用了new
下面配套有:delete[] m_pJPGBuffer;

hMem使用了GlobalAlloc,配套的使用了GlobalFree