Valgrind 错误:大小 4 的写入无效(但表示错误在 free() 中)
首先,这是 valgrind 给我的消息(这只是一个错误,我多次收到相同的消息)
==25248== Invalid write of size 4
==25248== at 0x4024B3A: free (vg_replace_malloc.c:366)
==25248== by 0x8048F5E: sthread_free_ctx (sthread_ctx.c:86)
==25248== by 0x80489C1: sthread_user_exit (sthread_user.c:105)
==25248== by 0x804883C: dispatcher (sthread_user.c:40)
==25248== Address 0x41a6148 is 65,376 bytes inside a block of size 65,536 free'd
==25248== at 0x4024B3A: free (vg_replace_malloc.c:366)
==25248== by 0x8048F5E: sthread_free_ctx (sthread_ctx.c:86)
==25248== by 0x80489C1: sthread_user_exit (sthread_user.c:105)
==25248== by 0x804883C: dispatcher (sthread_user.c:40)
我不明白它,因为我习惯在没有 malloc 足够的空间时收到此错误,那么为什么我会收到当我尝试释放某些东西时出错?正在写什么?
谢谢
First, here is the message valgrind gives me (this is just one error, I get the same message several times)
==25248== Invalid write of size 4
==25248== at 0x4024B3A: free (vg_replace_malloc.c:366)
==25248== by 0x8048F5E: sthread_free_ctx (sthread_ctx.c:86)
==25248== by 0x80489C1: sthread_user_exit (sthread_user.c:105)
==25248== by 0x804883C: dispatcher (sthread_user.c:40)
==25248== Address 0x41a6148 is 65,376 bytes inside a block of size 65,536 free'd
==25248== at 0x4024B3A: free (vg_replace_malloc.c:366)
==25248== by 0x8048F5E: sthread_free_ctx (sthread_ctx.c:86)
==25248== by 0x80489C1: sthread_user_exit (sthread_user.c:105)
==25248== by 0x804883C: dispatcher (sthread_user.c:40)
I dont understand it, because I am used to getting this error when I dont malloc enough space, so why am I getting the error when I am trying to free something?? what is being written?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
信息如此之少(特别是:没有代码)很难判断,但在我看来,您可能正在尝试在指针上调用
free
,该指针引用了内存区域的偏移量,该指针具有已通过之前调用free
释放。free
需要操作堆数据结构,因此它尝试写入内存区域也就不足为奇了。It is difficult to tell with so little information (particularly: no code), but it looks to me like you may be attempting to call
free
on a pointer which refers to an offset into a memory region which has already been freed by an earlier call tofree
.free
needs to manipulate the heap data structures, so it is not surprising that it is attempting to write to the memory region.