Tag: valgrind

C链接列表valgrind无效读取大小

我的链接列表和valgrind输出有问题。 这里没有进一步的说明是我的链表: typedef struct Map map; struct Map { void *address; double free_time; map* next; }*map_list; 使用虚拟头节点创建列表。 正如您所看到的,struct包含一个地址和一个空闲时间,我尝试将它们关联起来。 在find_and_free函数中,我使用时间搜索此列表,如果此时间小于列表中存储的时间,则取消分配已保存的地址。 然后我也解除了列表节点的释放。 这是用于查找任何小于我传递的空闲时间的函数。 如果它更小,我释放存储到列表中的地址,然后调用delete_map_node函数也解除分配列表的节点。 void find_and_free_address(map *root, double mtime) { map *current = root->next; assert(current); while(current) { if(current->free_time free_time); printf(“The map contains an address that is time to free\n”); //free_allocated_address(&current->address); free(current->address); delete_map_node(map_list, current->free_time); //delete(map_list,current->free_time); //return next; } […]

在函数中更改指针的值

我想在函数中更改变量的值。 我的代码是这样的: void change(char *buf){ char str = “xxxxxxx”; *buf = &str; } int main(){ char *xxx = NULL; change(xxx); } 当我用valgrind调试时,它说: ==3709== Invalid write of size 1 ==3709== at 0x80483CA: change (test.c:5) ==3709== by 0x80483E5: main (test.c:10) ==3709== Address 0x0 is not stack’d, malloc’d or (recently) free’d ==3709== ==3709== ==3709== Process terminating with default […]

Valgrind在pthread_spin_lock中挂起消耗100%的CPU

我的C ++multithreading应用程序在valgrind版本3.8.0和最新版本的pthread_spin_lock中挂起。 但它不会发生在3.6.0,3.6.1和3.7.0中。 有人知道任何解决方法吗?

在Mac OS X上由pclose()引起的Valgrind错误

尝试pclose()之前用popen()打开的管道时,我遇到了valgrind错误。 错误发生在Mac OS X上,但不发生在Linux上。 请考虑以下示例: #include #include int main() { FILE *fp; char buf[4096]; if (!(fp = popen(“ls”, “r”))) exit(-1); while (fscanf(fp, “%s”, buf) == 1) printf(“%s\n”, buf); pclose(fp); return 0; } 我在Mac上得到以下valgrind错误(OS X 10.6.7,valgrind版本3.6.0),除非我删除了pclose()调用: ==21455== Conditional jump or move depends on uninitialised value(s) ==21455== at 0xB1992: pclose (in /usr/lib/libSystem.B.dylib) ==21455== by 0x1F16: main (in […]

如何让Valgrind记录所有分配?

即使没有发现内存错误,我也想让Valgrind记录分配。 如何才能做到这一点?

用pthreads泄漏内存

我正在使用pthreads并根据valgrind我泄漏内存,就像使用pthread_create时valgrind内存泄漏错误一样 最好的答案是,如果你pthread_join所有的线程,这个内存将被回收,但它不适合我。 pthread_t threads[NUM_THREADS]; … for (i = 0; i < NUM_THREADS; i++) { pthread_create(&threads[i], &attr, Worker, NULL); } … for (i = 0; i < NUM_THREADS; i++) { pthread_join(threads[i], NULL); } valgrind输出 ==2707== HEAP SUMMARY: ==2707== in use at exit: 954 bytes in 4 blocks ==2707== total heap usage: 7,717 allocs, 7,713 frees, 79,563 […]

打印分配的字符串时,valgrind报告错误

代码在这里: #include #include #include int main() { char* buf = malloc(3); strcpy(buf, “hi”); printf(“%s\n”, buf); free(buf); } 它编译为: gcc ac && valgrind ./a.out 错误消息在这里: ==1421== Memcheck, a memory error detector ==1421== Copyright (C) 2002-2010, and GNU GPL’d, by Julian Seward et al. ==1421== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info ==1421== Command: […]

Valgrind …大小为8的块中的4个字节

尝试释放列表后,我在Valgrind中收到此错误。 print_list将列表转储到syslog。 我非常有信心输出是正确的。 Valgrind的: ==7028== 1 errors in context 1 of 10: ==7028== Invalid read of size 4 ==7028== at 0x8049603: free_list (list.c:239) ==7028== by 0x80488B5: m61_close_for_valgrind (m61.c:36) ==7028== by 0x8048825: main (mytest.c:19) ==7028== Address 0x420006c is 4 bytes inside a block of size 8 free’d ==7028== at 0x4028F0F: free (vg_replace_malloc.c:446) ==7028== by 0x804960C: free_list […]

Valgrind合法的“可能丢失”字节的例子

我看到valgrind将内存泄漏分类为: 肯定输了 间接失去了 可能会丢失 仍然可以到达 抑制 我刚刚解决了“可能丢失”是主要问题的漏洞。 文档说 :“ 可能丢失意味着你的程序正在泄漏内存,除非你使用可能导致它们指向已分配块的中间的指针做不寻常的事情;请参阅用户手册以了解某些可能的原因” 我可以知道一个例子“ 使用可能导致它们指向已分配块的中间的指针做不寻常的事情 ”吗? 我的意思是一个例子,虽然valgrind报道了“可能丢失”但可以忽略。 使用指针使valgrind抱怨的一个例子,但同时以这种方式使用指针在某种程度上是合法的 谢谢

valgrind条件跳转或移动取决于未初始化的值,这是否表示内存泄漏?

我正面临着代码中的内存泄漏问题,当它运行时,堆继续增加到最大值,我需要重新启动服务,我运行top命令,看到每当我调用服务中的场景时堆都在增加。 我用valgrind运行服务, valgrind –log-file=log-feb19.txt –leak-check=full –show-reachable=yes –track-origins=yes myservice 当我运行场景时,我没有看到任何明显丢失或可能丢失的块,但我看到很多条件跳转或移动取决于未初始化的值错误。 这些是否会导致内存泄漏? 我得到的例子: ==27278== Conditional jump or move depends on uninitialised value(s) ==27278== at 0xC90D91E: xcsFreeMemFn (in /apps/opt/mqm/lib64/libmqmcs_r.so) …….. ==27278== Uninitialised value was created by a heap allocation ==27278== at 0x4A078B8: malloc (vg_replace_malloc.c:270) ==27278== by 0xC90E32F: xcsGetMemFn (in /apps/opt/mqm/lib64/libmqmcs_r.so) 有人可以帮忙吗