Valgrind 错误:大小 4 的写入无效(但表示错误在 free() 中)

发布于 2024-12-10 02:57:32 字数 762 浏览 0 评论 0原文

首先,这是 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦与时光遇 2024-12-17 02:57:32

信息如此之少(特别是:没有代码)很难判断,但在我看来,您可能正在尝试在指针上调用 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 to free. free needs to manipulate the heap data structures, so it is not surprising that it is attempting to write to the memory region.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文