C++代码的一些报错记录

运行报错

重复析构double free

报错提示

free(): double free detected in tcache 2

DEBUG定位报错位置

Eigen/src/Core/util/Memory.h文件位置

/** \internal Frees memory allocated with conditional_aligned_malloc */
template<bool Align> EIGEN_DEVICE_FUNC inline void conditional_aligned_free(void *ptr)
{
  aligned_free(ptr);
}

报错代码与报错原因

bool optimieze()
{
		/*
		....
		使用g2o一些定义优化器以及添加顶点的操作
		*/

	for(int i = 0; i < 5; i++)
	{
		/*
		....
		使用g2o一些定义边和进行优化的操作
		*/
		bool correct = fun();
		if(correct)
		{
			return false;
		}
		else
		{
			// 这里没写返回值
		}
	}
	// 报错原因:这一行缺少了返回值,应该加上代码 <return true;>这样就不会报错了
}

原因是一个bool类型的函数有一个if分支会导致没有返回值,完后函数退出时调用顶点的析构函数时候导致了重复释放内存的报错。

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值