valgrind

How to debug stack-overwriting errors with Valgrind?

余生长醉 提交于 2021-02-07 06:34:52
问题 I just spent some time chasing down a bug that boiled down to the following. Code was erroneously overwriting the stack, and I think it wrote over the return address of the function call. Following the return, the program would crash and stack would be corrupted. Running the program in valgrind would return an error such as: vex x86->IR: unhandled instruction bytes: 0xEA 0x3 0x0 0x0 ==9222== valgrind: Unrecognised instruction at address 0x4e925a8. I figure this is because the return jumped to

How to debug stack-overwriting errors with Valgrind?

a 夏天 提交于 2021-02-07 06:34:00
问题 I just spent some time chasing down a bug that boiled down to the following. Code was erroneously overwriting the stack, and I think it wrote over the return address of the function call. Following the return, the program would crash and stack would be corrupted. Running the program in valgrind would return an error such as: vex x86->IR: unhandled instruction bytes: 0xEA 0x3 0x0 0x0 ==9222== valgrind: Unrecognised instruction at address 0x4e925a8. I figure this is because the return jumped to

How to debug stack-overwriting errors with Valgrind?

北城余情 提交于 2021-02-07 06:32:10
问题 I just spent some time chasing down a bug that boiled down to the following. Code was erroneously overwriting the stack, and I think it wrote over the return address of the function call. Following the return, the program would crash and stack would be corrupted. Running the program in valgrind would return an error such as: vex x86->IR: unhandled instruction bytes: 0xEA 0x3 0x0 0x0 ==9222== valgrind: Unrecognised instruction at address 0x4e925a8. I figure this is because the return jumped to

Is my valgrind installation broken?

柔情痞子 提交于 2021-02-04 08:17:45
问题 I have this basic Hello World code : #include <stdio.h> int main() {printf("Hello World !"); return 0;} Then valgrind return me this summary : HEAP SUMMARY: ==17840== in use at exit: 22,114 bytes in 160 blocks ==17840== total heap usage: 176 allocs, 16 frees, 28,258 bytes allocated ==17840== ==17840== LEAK SUMMARY: ==17840== definitely lost: 7,960 bytes in 63 blocks ==17840== indirectly lost: 6,888 bytes in 8 blocks ==17840== possibly lost: 72 bytes in 3 blocks ==17840== still reachable: 32

c++ 内存管理

和自甴很熟 提交于 2021-02-02 05:00:50
Valgrind 是个开源的工具,功能很多。 Memcheck是一个内存错误检测器。它有助于使你的程序,尤其是那些用C和C++写的程序,更加准确。 Cachegrind是一个缓存和分支预测分析器。它有助于使你的程序运行更快,分析CPU的cache命中率、丢失率,用于进行代码优化。。 Callgrind是一个调用图缓存生成分析器。它与Cachegrind的功能有重叠,但也收集Cachegrind不收集的一些信息,检测程序代码的运行时间和调用过程,以及分析程序性能。 Helgrind是一个线程错误检测器。它有助于使你的多线程程序更加准确,用于检查多线程程序的竞态条件。 DRD也是一个线程错误检测器。它和Helgrind相似,但使用不同的分析技术,所以可能找到不同的问题。 Massif是一个堆分析器。它有助于使你的程序使用更少的内存。 DHAT是另一种不同的堆分析器。它有助于理解块的生命期、块的使用和布局的低效等问题。 SGcheck是一个实验工具,用来检测堆和全局数组的溢出。它的功能和Memcheck互补:SGcheck找到Memcheck无法找到的问题,反之亦然。 BBV是个实验性质的SimPoint基本块矢量生成器。它对于进行计算机架构的研究和开发很有用处 memcheck valgrind --tool=memcheck --leak-check=full --show

used uninitialized value of size 8 by strcat using C++ with Valgrind while saving data

断了今生、忘了曾经 提交于 2021-01-29 20:52:00
问题 I am aware of existence of similar posts about segmentation fault, however, I have a bit of a specific issue that I need some guidance with. I am working on a code, it's a simulation that calculates some values and saves all of these values in a document that could be used later for data analysis. I am getting a segmentation fault error when I run the code with Valgrind in debugging mode I get the following: "used uninitialized value of size 8": Iteration = 100 t=10.1000000 ==26716==

OpenCL clCreateContextFromType function results in memory leaks

限于喜欢 提交于 2021-01-29 18:39:50
问题 I ran valgrind to one of my open-source OpenCL codes (https://github.com/fangq/mmc), and it detected a lot of memory leaks in the OpenCL host code. Most of those pointed back to the line where I created the context object using clCreateContextFromType . I double checked all my OpenCL variables, command queues, kernels and programs, and made sure that they are all properly released, but still, when testing on sample programs, every call to the mmc_run_cl() function bumps up memory by 300MB

Memory leaks in pthread even if the state is detached

穿精又带淫゛_ 提交于 2021-01-29 18:37:55
问题 I am learning pthreads programming. I understood that there are two states of thread: 1. Joinable 2. Detachable In case of Joinable, we need to call pthread_join to free the resources(stack), whereas in case of detached there is no need to call pthread_join and the resources will be freed on thread exit. I wrote a sample program to observe the behavior #include <stdio.h> #include <pthread.h> #include <stdlib.h> void *threadFn(void *arg) { pthread_detach(pthread_self()); sleep(1); printf(

OpenCL clCreateContextFromType function results in memory leaks

旧街凉风 提交于 2021-01-29 12:16:56
问题 I ran valgrind to one of my open-source OpenCL codes (https://github.com/fangq/mmc), and it detected a lot of memory leaks in the OpenCL host code. Most of those pointed back to the line where I created the context object using clCreateContextFromType . I double checked all my OpenCL variables, command queues, kernels and programs, and made sure that they are all properly released, but still, when testing on sample programs, every call to the mmc_run_cl() function bumps up memory by 300MB

valgrind shows memory leak even after memory free

坚强是说给别人听的谎言 提交于 2021-01-29 06:30:03
问题 so I have the file Countries.c which contains: typedef struct City* pCity; typedef struct Country* pCountry; typedef struct Territory* pTerritory; struct City{ char* name; char* food; int population; }; struct Country{ char *name; int numCities; pCity cities; pTerritory countryTerr; }; struct Territory{ int x1; int x2; int y1; int y2; }; void deleteCountry(pCountry country){ if(country != NULL){ int num_of_cities = country->numCities; for(int i = 0 ; i<num_of_cities; i++){ if (country->cities