cpp queue bug: malloc.c:2379

错误:

malloc.c:2379: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.

代码:

 bool visit[n];
 queue<Node<T> > Q;
 cout << "*******55551\n";
 int s_idx = mp[s.name];
 cout << "*******55552\n";
 visit[s_idx] = true;
 cout << "*******55553\n";
 Q.push(s);
 cout << "*******55554\n";
 Node<T> tmp_s;
 cout<<"*******5555\n";

报错:

*******55551
*******55552
*******55553
edgeOverlap: malloc.c:2379: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
Aborted (core dumped)

猜测是内存分配的原因?尝试:
1.指定queue的容器

std::queue<int, std::list<int>> values;

不行,一样的报错

2.使用deque
不行,queue就是用deque实现的,今天才学到 😦

3.clear queue

 //clear queue
 std::queue<Node<T> > empty;
 std::swap(Q, empty);

不行,看来不是内存耗尽,调用结束应该会析构

4.https://stackoverflow.com/questions/64690176/malloc-c2379-sysmalloc-assertion-failed
没有帮助

5.应该是内存泄漏
https://stackoverflow.com/questions/67397359/sysmalloc-assertion-failed-in-c

g++ edgeOverlap.cpp -o edgeOverlap -fsanitize=address
SUMMARY: AddressSanitizer: 11244 byte(s) leaked in 67 allocation(s).

undefined behavior:
https://stackoverflow.com/questions/2397984/undefined-unspecified-and-implementation-defined-behavior

怎么解决呢?

找到原因了,不在这段代码,是set_union里存结果的数组没给足够的空间:

vector<int> unionv_k(2*n); // Neibors(i) union Neibors(j)
std::vector<int>::iterator ls2 = std::set_union(neighbors1_k.begin(), neighbors1_k.end(), neighbors2_k.begin(), neighbors2_k.end(), unionv_k.begin());

下次还是空间开大一点。。。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值