setcontext()Valgrind读取大小为8

时间:2013-02-10 19:14:44

标签: c valgrind

我目前面临一个非常奇怪的问题。我正在构建一个库并将其链接到我的程序。一切运行良好,没有分段错误(也用gdb检查)但是当我用Valgrind运行程序时,它会疯狂地说道:

==11972== Invalid read of size 8
==11972==    at 0x509509C: setcontext (setcontext.S:73)
==11972==    by 0x509764F: ??? (in /lib/x86_64-linux-gnu/libc-2.15.so)
==11972==  Address 0x541f060 is 128 bytes inside a block of size 936 alloc'd
==11972==    at 0x4C2B3F8: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11972==    by 0x402090: environment_get (env.c:99)
==11972==    by 0x401ED6: environment_new (env.c:36)
==11972==    by 0x40124B: thr_new (thr.c:156)
==11972==    by 0x400EBE: main (itest1.c:31)

但程序运行正常,setcontext有一个正确的malloced参数没有问题。我有什么理由担心这些台词吗?

由于

1 个答案:

答案 0 :(得分:0)

该线程迟了七年,但是:我通过确保堆栈至少为newDict= { "2020" : { '2020-04-10: 70.0 '2020-04-13: 100.0, → (i.e., 70.0 + 30.0) }, "2019" : { '2020-04-10: 50.0, }, 来解决此问题。因此,以下代码可以解决此问题:

SIGSTKSZ

然后,在清理它时,您可以做一些负责任的事情,例如:

#include <valgrind/valgrind.h>

//technically, the below doesn't need to be dynamically allocated, but for demonstration:
ucontext_t context = (ucontext_t*) malloc(sizeof(ucontext_t));

getcontext(&context);
void* stack = malloc(SIGSTKSZ);
VALGRIND_STACK_REGISTER(stack, stack + SIGSTKSZ);
context->uc_stack.ss_sp     = stack;
context->uc_stack.ss_size   = SIGSTKSZ;
context->uc_stack.ss_flags  = 0;
sigemptyset(&context->uc_sigmask);
context->uc_link            = &someOtherContextToGoToAfterwards;
makecontext(context, functionForContextToExecute);