标签: valgrind

valgrind,分析计时器到期了吗?

我尝试使用valgrind来描述一个简单的c prog:

[zsun @ nel6005001~] $ valgrind --tool = memcheck ./fl.out
== 2238 == Memcheck,内存错误检测器
== 2238 == Copyright(C)2002-2009,GNU GPL'd,Julian西沃德等人.
== 2238 ==使用Valgrind-3.5.0和LibVEX; 重新运行-h版权信息
== 2238 ==命令:./ fl.out
== 2238 ==
== 2238 ==
== 2238 == HEAP SUMMARY:
== 2238 ==在退出时使用:1,168字节in 1个块
== 2238 ==总堆使用量:1个allocs,0个frees,1,168个字节分配
== 2238 ==
== 2238 == LEAK SUMMARY:
== 2238 ==绝对丢失:0个块中的0个字节
== 2238 = =间接丢失:0个块中的0个字节
== 2238 ==可能丢失:0个块中的0个字节
== 2238 ==仍然可达:1个块中的1,168个字节
== 2238 ==抑制:0个块中的0个字节
== 2238 ==重新运行--leak-check = full以查看泄漏内存的详细信息
== 2238 ==
== 2238 …

valgrind

10
推荐指数
2
解决办法
7008
查看次数

C内存泄漏,尽管免费

在用Valgrind调试我的程序时,我发现了一个内存泄漏,尽管我认为是有效的免费调用.首先,分配内存并存储它的代码:

    row = malloc(sizeof(Row));
    row->columns = malloc(sizeof(char*) * headcnt);
    row->numcol  = 0;

    ...

    row->numcol    = colcnt;
    rows           = realloc(rows, (rowcnt+1) * sizeof(Row));
    rows[rowcnt++] = *row;
Run Code Online (Sandbox Code Playgroud)

负责尝试释放内存的代码:

void cleanUp(){
    int i = 0;
    int j = 0;

    for (i = 0; i < rowcnt; i++){
        for (j = 0; j < rows[i].numcols; j++){
            free(rows[i].columns[j]);
        }
        free(&rows[i]);
    }
    free(rows); 
    exit(0);
}
Run Code Online (Sandbox Code Playgroud)

Row的声明:

typedef struct {
    char** columns;
    unsigned short int numcol;
} Row;

Row* rows = NULL;
Run Code Online (Sandbox Code Playgroud)

更糟糕的是,这个程序有时会导致glibc错误,free(&rows[i])因为抱怨双重免费.我是C的新手,并且会感谢有人可能提出的任何指针(咳咳).

c memory valgrind pointers

10
推荐指数
2
解决办法
579
查看次数

Valgrind抱怨"写入8号无效"

我正在开发一个小型的爱好项目(www.github.com/AzP/GLSL-Validate),我已经采用旧代码(过多的c和小c ++用于我自己的口味,但是,嘿,你能做什么? )我正试图在Linux和Windows上运行它.我有几次崩溃(现在有希望修复),但是自从我开始运行Valgrind以找到问题后,我一直想要解决我得到的抱怨.

我只是看不出这个代码有什么问题(除了在Valgrind投诉方面很难读出好看的"神奇数字").

我用以下命令运行Valgrind valgrind --track-origins=yes ./Program

291 //
292 //   Malloc a string of sufficient size and read a string into it.
293 //
294 # define MAX_SOURCE_STRINGS 5
295 char** ReadFileData(char *fileName)
296 {
297     FILE *in = fopen(fileName, "r");
298     char *fdata;
299     int count = 0;
300     char**return_data=(char**)malloc(MAX_SOURCE_STRINGS+1);
301 
302     //return_data[MAX_SOURCE_STRINGS]=NULL;
303     if (!in) {
304         printf("Error: unable to open input file: %s\n", fileName);
305         return 0;
306     }
307 
308     // Count …
Run Code Online (Sandbox Code Playgroud)

c debugging valgrind memory-management

10
推荐指数
1
解决办法
3万
查看次数

Valgrind未处理的指令字节错误

为了在我的应用程序中基于Liv555库搜索内存泄漏,我尝试使用valgrind运行它.它会导致以下错误:

vex amd64->IR: unhandled instruction bytes: 0xC5 0xF9 0x57 0xC0 0xC5 0xFA 0x10 0x15
Run Code Online (Sandbox Code Playgroud)

在另一台计算机上运行它不会导致此错误(它运行正常),所以我希望这是一些库版本的结果.这可能是问题吗?如果是这样,有谁知道哪个库可能导致错误?valgrind带有-v -v选项的输出位于此处.

valgrind

10
推荐指数
1
解决办法
6000
查看次数

解释valgrind错误无效的写入大小4

我最近试图追踪我正在使用valgrind的程序中的一些错误,我得到的错误之一是:

==6866== Invalid write of size 4
==6866==    at 0x40C9E2: superneuron::read(_IO_FILE*) (superneuron.cc:414)
Run Code Online (Sandbox Code Playgroud)

违规行#414读取

amplitudes__[points_read] = 0x0;
Run Code Online (Sandbox Code Playgroud)

和振幅_早先被定义为

uint32_t * amplitudes__ = (uint32_t* ) amplitudes;
Run Code Online (Sandbox Code Playgroud)

现在显然uint32_t是4个字节长,所以这是写入大小,但有人可以告诉我它为什么无效?

gcc valgrind

10
推荐指数
1
解决办法
2万
查看次数

valgrind` --track-fds = yes`没有fds 0,1,2

我正在使用以下设置运行valgrind : valgrind --tool=memcheck --tool=callgrind --num-callers=20 --track-fds=yes --error-exitcode=1 CMD. 特别是,--track-fds=yes按照需要工作,但由于fds 0,1,2应该打开,每次运行都会失败.但是,我不想放弃--track-fds,因为它肯定会提供有意义的信息.那么,是否存在valgrind选项/方法来跟踪除0,1,2之外的fds?

==5872== FILE DESCRIPTORS: 3 open at exit.
==5872== Open file descriptor 2:
==5872==    <inherited from parent>
==5872== 
==5872== Open file descriptor 1:
==5872==    <inherited from parent>
==5872== 
==5872== Open file descriptor 0: /dev/pts/0
==5872==    <inherited from parent>
==5872== 
==5872== 
==5872== Events    : Ir
==5872== Collected : 3081079256
==5872== 
==5872== I   refs:      3,081,079,256
Run Code Online (Sandbox Code Playgroud)

valgrind

10
推荐指数
1
解决办法
4621
查看次数

设置返回值时忽略"仍可访问"

在CI系统中,我使用valgrind运行一系列测试,0如果valgrind没有找到错误,我期望返回值1.测试本身成功运行并返回0.

error-exitcode似乎是为了:

--error-exitcode=<number> exit code to return if errors found [0=disable]
Run Code Online (Sandbox Code Playgroud)

现在我有一个still reachable从第三方库生成的程序.不理想,但没关系.我尝试still reachable通过调用来定义这不是错误:

valgrind --errors-for-leak-kinds=definite,indirect,possible --error-exitcode=1 ./tests
Run Code Online (Sandbox Code Playgroud)

打印

==9198== LEAK SUMMARY:
==9198==    definitely lost: 0 bytes in 0 blocks
==9198==    indirectly lost: 0 bytes in 0 blocks
==9198==      possibly lost: 0 bytes in 0 blocks
==9198==    still reachable: 392 bytes in 4 blocks
==9198==         suppressed: 0 bytes in 0 blocks
Run Code Online (Sandbox Code Playgroud)

但仍然返回1.

still reachable在返回值中有没有办法忽略?

c++ valgrind

10
推荐指数
1
解决办法
442
查看次数

Valgrind C++内存在空文件中泄漏

我在valgrind中遇到"额外"内存泄漏问题.例如,我创建了一个名为temp.cpp的测试程序:

int main() { return 0; }
Run Code Online (Sandbox Code Playgroud)

在终端,我运行:

>> g++ -o temp.out temp.cpp
>> valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all ./temp.out
Run Code Online (Sandbox Code Playgroud)

这会导致几次内存泄漏.怎么会这样?

==4438== LEAK SUMMARY:
==4438==    definitely lost: 4,120 bytes in 2 blocks
==4438==    indirectly lost: 2,288 bytes in 6 blocks
==4438==      possibly lost: 8,336 bytes in 99 blocks
==4438==    still reachable: 6,440 bytes in 13 blocks  
==4438==         suppressed: 5,020 bytes in 73 blocks
Run Code Online (Sandbox Code Playgroud)

我试过运行其他.cpp文件,我得到完全相同的泄漏摘要.大约一个月前,当我尝试时,没有错.我可能已经升级了Xcode或其他东西,如果这可能是问题(?).这些是我对g ++的设置:

配置为:

--prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1
Run Code Online (Sandbox Code Playgroud)

Apple LLVM版本6.1.0(clang-602.0.53)(基于LLVM 3.6.0svn)目标:x86_64-apple-darwin15.0.0线程模型:posix

c++ macos xcode valgrind

10
推荐指数
1
解决办法
998
查看次数

valgrind - 地址是一个大小为16的块之前的8个字节

我遇到了"消化"valgrind输出的问题.这是一个片段:

==15145== Invalid write of size 8
==15145==    at 0x40168E: split_node_at_letter (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x4018E7: pass_word_further (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x401A35: insert_word (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x401BD5: main (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==  Address 0x52237d8 is 8 bytes before a block of size 16 alloc'd
==15145==    at 0x4C29BCF: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==15145==    by 0x401063: add_to_trie_word_list (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x40173B: pass_word_further (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x40183D: pass_word_further (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x401906: pass_word_further (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii)
==15145==    by 0x401A35: insert_word (in /home/pgolinski/Dokumenty/Programowanie/git/dictionary/trii) …
Run Code Online (Sandbox Code Playgroud)

c valgrind

9
推荐指数
1
解决办法
1万
查看次数

callgrind profiling是否受其他进程的影响?

我想用callgrind来描述我的应用程序.现在,由于需要很长时间,同时我继续在同一台机器上进行网页浏览,编译和其他密集型任务.

我是否偏向分析结果?我期待这一点,因为valgrind使用模拟CPU,其他外部进程不应该干扰valgrind执行.我对吗?

profiling valgrind callgrind

9
推荐指数
1
解决办法
279
查看次数

标签 统计

valgrind ×10

c ×3

c++ ×2

callgrind ×1

debugging ×1

gcc ×1

macos ×1

memory ×1

memory-management ×1

pointers ×1

profiling ×1

xcode ×1