Tag: valgrind

glib2实际上是否通过ALWAYS-MALLOC泄漏内存?

这个问题与其他许多问题不重复,因为我确实使用了G_DEBUG=gc-friendly和G_SLICE=always-malloc这是源代码: #include int main (int argc, char *argv[]) { GHashTable *ht; ht=g_hash_table_new(g_str_hash,g_str_equal); g_hash_table_insert(ht,”foo”,”bar”); g_hash_table_destroy(ht); return 0; } 以下是valgrind在此代码上的输出: # G_DEBUG=gc-friendly G_SLICE=always-malloc valgrind –leak-check=full –show-reachable=yes ./test_vg ==1880== Memcheck, a memory error detector ==1880== Copyright (C) 2002-2010, and GNU GPL’d, by Julian Seward et al. ==1880== Using Valgrind-3.6.0 and LibVEX; rerun with -h for copyright info ==1880== […]

makefile中的gdb和valgrind

我有一个非常基本的问题。 我确实在这里环顾四周http://www.cs.cmu.edu/~gilpin/tutorial/但仍然怀疑.. 考虑以下makefile(在之前的问题中也给出了它) all: clients.so simulator backup LD_PRELOAD=/home/Juggler/client/clients.so ./simulator backup: backup.c libclient.a gcc backup.c -o backup -L /home/Juggler/client -L. -lclient -ldl simulator: simulator.c libclient.a gcc -g simulator.c -o simulator -L /home/Juggler/client -L. -lclient -ldl -pthread libclient.a: libclient.o client.o ar rcs libclient.a libclient.o client.o libclient.o:libclient.c gcc -c libclient.c -o libclient.o -pthread clients.so: client.o client_invoke.o ld -shared […]

最常见的子序列:为什么这是错的?

int lcs(char * A, char * B) { int m = strlen(A); int n = strlen(B); int *X = malloc(m * sizeof(int)); int *Y = malloc(n * sizeof(int)); int i; int j; for (i = m; i >= 0; i–) { for (j = n; j >= 0; j–) { if (A[i] == ‘\0’ || […]

不可能发生了! 这是什么意思?

我遇到了一个有趣的运行时错误。 我认为这是某种内存泄漏。 我写了以下程序: C代码: #include #include #include #include #include #define PRECISION 4096 #define DECIMAL_POINT 1 #define NULL_TERMINATOR 1 void gatherSquares(const uint32_t limit, uint32_t ** const arr, uint32_t * const count); uint32_t inList(const uint32_t n, const uint32_t * const arr, const uint32_t count); void print_help(const char * const str); int main(int argc, char* argv[]) { uint32_t […]

用valgrind检查fftw3

在我的程序的一个步骤中,我需要卷积图像。 为此,我使用fftw3提供的function。 当我在我的程序上运行valgrind ,我得到了这个堆栈跟踪。 我的函数叫做fftw3 ,它运行fftw3的fftw_plan_dft_r2c_2d两次(一次在图像上,一次在卷积内核上。为了使它更具可读性,我删除了所有地址和进程ID。 HEAP SUMMARY: in use at exit: 62,280 bytes in 683 blocks total heap usage: 178,271 allocs, 177,588 frees, 36,617,058 bytes allocated 3,304 (24 direct, 3,280 indirect) bytes in 1 blocks are definitely lost in loss record 129 of 131 at : malloc (vg_replace_malloc.c:291) by : fftw_malloc_plain (in ./prog) by […]

Valgrind报告说getaddrinfo正在泄漏内存?

我一直在我们的项目上运行Valgrind,并且valgrind报告说,尽管在函数的底部调用了freeaddrinfo,但是从getaddrinfo的调用中已经丢失了内存。 知道是什么原因造成的吗? int tcp_connect(char *address, char *port) { //printf(“%s\n “, address); int status, sockfd; struct addrinfo hints, *servinfo, *p; memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype= SOCK_STREAM; status = getaddrinfo(address,port,&hints,&servinfo); if(status != 0){ printf(“tcpconnect: getaddrinfo failed\n”); } for(p = servinfo; p != NULL; p = p->ai_next) { sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol); if(sockfd == […]

条件跳转或移动取决于未初始化的值

我一直在努力解决这个问题一段时间,寻找所有可能的解决方案。 我是C的新手,所以我很难。 我知道我有一些未初始化的变量,但我找不到它们。 我正在尝试打印矩阵。 这是构造函数: BoardP createNewBoard(int width, int high) { BoardP board = (BoardP) malloc(sizeof(Board)); if (board == NULL) { reportError(MEM_OUT); return NULL; } board->height = high; board->width = width; board->board = (char**) malloc(high * sizeof(char*)); int i; for (i=0; iboard[i] = (char*) malloc(width * sizeof(char)); if (board->board[i] == NULL) { freeTempBoard(board,i); return NULL; […]

如何在分析项目时解决dyld和localtime泄漏问题?

我在描述我的来源。 当我运行valgrind时,我看到一些在退出时仍处于活动状态的分配。 以下是摘要: $ valgrind –track-origins=yes –show-reachable=yes –leak-check=full $BINARY … ==20235== LEAK SUMMARY: ==20235== definitely lost: 0 bytes in 0 blocks ==20235== indirectly lost: 0 bytes in 0 blocks ==20235== possibly lost: 0 bytes in 0 blocks ==20235== still reachable: 20,228 bytes in 37 blocks ==20235== suppressed: 0 bytes in 0 blocks ==20235== 负责的图书馆是: dyld […]

什么可以导致Valgrind堆栈跟踪中的奇怪地址?

(这个问题与从valgrind输出中过滤掉垃圾有关)。 我正在尝试调试一个大部分项目中的内存泄漏,这个项目大部分都不在我的手中 – 它是代码库的一个分支,大约有数百万行代码,尽管大部分可能与代码库无关。我正在努力的一小部分。 由于手工查看它非常困难,我正在尝试使用valgrind来追踪泄漏。 问题是堆栈跟踪看起来像这样: ==83597== 920 bytes in 1 blocks are possibly lost in loss record 750 of 864 ==83597== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==83597== by 0x548EF93: myproject_malloc (mysourcefile.c:48) ==83597== by 0x4F13FD5: ??? (in /path/to/project/library-version.so) ==83597== by 0xFFEFFFD5F: ??? ==83597== by 0x38F: ??? ==83597== by 0xFFEFFFE5F: ??? ==83597== by 0xF: ??? ==83597== […]

C:分段错误:GDB:

我有一个函数shortestPath(),它是Dijkstra算法的修改实现,用于我正在为我的comp2类工作的棋盘游戏AI。 我已经浏览了网站并使用gdb和valgrind我确切知道了段错误发生的位置(几小时前就知道了),但无法弄清楚导致问题的是什么未定义的行为或逻辑错误。 发生问题的函数被调用大约10倍并按预期工作,直到它与GDB发生段错误:“错误读取变量:无法访问内存”和valgrind:“读取大小为8的无效” 通常情况下这就足够了,但我无法解决这个问题。 也欢迎任何一般建议和提示…谢谢! GDB: https : //gist.github.com/mckayryan/b8d1e9cdcc58dd1627ea Valgrind: https : //gist.github.com/mckayryan/8495963f6e62a51a734f 以下是发生段错误的function: static void processBuffer (GameView currentView, Link pQ, int *pQLen, LocationID *buffer, int bufferLen, Link prev, LocationID cur) { //printLinkIndex(“prev”, prev, NUM_MAP_LOCATIONS); // adds newly retrieved buffer Locations to queue adding link types appendLocationsToQueue(currentView, pQ, pQLen, buffer, bufferLen, cur); // calculates distance […]