WTHunt 2016-03-09 11:19 采纳率: 30.8%
浏览 1665
已结题

关于内存delete报错的问题,以下代码在最后delete的时候

(safe_deletevec是宏定义,如果指针不等于NULL,就删除并置NULL),就会报错,说是写入冲突,应该没有越界,可是就是想不通为什么出错,麻烦各位给些建议

short Nobone=m_sMinValue+50;
int m_nValueMax=0;
for(int i = 0; i < m_nOriImagePiece; i++)
{
int k = i*m_nWidth*m_nHeight;
for (int m = 0; m < m_nHeight; m++)
{
int v = m*m_nWidth + k;
for (int n = 0; n < m_nWidth; n++)
{
int a = ((short*)m_pProcessArray->GetDcmArray()[i]->GetData())[m_nWidth*m + n];
if (a>Nobone)
{
short m_nRadi = EDTdate[v+n];
if (m_nRadi>m_nValueMax)
m_nValueMax = m_nRadi;
}
}
}
}

m_nValueMax = m_nValueMax + 1;
short* occurs = new short[m_nValueMax];
memset(occurs , 0 ,sizeof(short)*m_nValueMax);

for(int i = 0; i < m_nOriImagePiece; i++)
{
    int k = i*m_nWidth*m_nHeight;
    for (int m = 0; m < m_nHeight; m++)
    {
        int v = m*m_nWidth + k;
        for (int n = 0; n < m_nWidth; n++)
        {
            int a = ((short*)m_pProcessArray->GetDcmArray()[i]->GetData())[m_nWidth*m + n];
            if (a>Nobone)
            {
               short m_nRadi = EDTdate[v+n];
               occurs[m_nRadi] = 1;
            }
        }
    }
}

numRadii = 0;
for (int i=0;i<m_nValueMax;i++)
{
    if (occurs[i])
        numRadii++;
}
//make an index of the distance-squared values
short* distSqIndex = new short[m_nValueMax];
memset(distSqIndex,0,sizeof(short)*m_nValueMax);
short* distSqValues = new short[numRadii];
memset(distSqValues,0,sizeof(short)*numRadii);
int indDs = 0;
for (int i=0;i<m_nValueMax;i++)
{
    if (occurs[i])
    {
        distSqIndex[i] = indDs;
        distSqValues[indDs++]=i;
    }
}
Safe_DeleteVec(occurs);
  • 写回答

4条回答 默认 最新

  • cxsmarkchan 2016-03-09 11:37
    关注

    检查两个地方:
    1. short m_nRadi = EDTdate[v+n];得到的m_nRadi是否可能越界
    2. occurs指向数组,删除时应该是delete[] occurs而不是delete occurs
    希望对你有帮助。

    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀