valgrind

What happens if I set a value outside of the memory allocated with calloc?

不羁的心 提交于 2020-01-25 05:44:26
问题 Consider the following: int* x = calloc(3,sizeof(int)); x[3] = 100; which is located inside of a function. I get no error when I compile and run the program, but when I run it with valgrind I get an "Invalid write of size 4". I understand that I am accessing a memory place outside of what I have allocated with calloc, but I'm trying to understand what actually happens. Does some address in the stack(?) still have the value 100? Because there must certainly be more available memory than what I

Prevent valgrind for checking memory leaking in shared libraries linked with our application

半腔热情 提交于 2020-01-24 20:56:34
问题 valgrind-3.6.0.SVN-Debian gcc (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5 2.6.35-22-generic I am using valgrind to detect memory errors in our code. However, are application uses some third party libraries (shared library). When we start to capture using valgrind. It goes into this library, and displays many memory errors with this library. So it is difficult to check our application due to this. There is many to go through. It is possible to configure valgrind to only check our source code and not

Helgrind for Windows?

蓝咒 提交于 2020-01-24 13:03:08
问题 Helgrind is a Valgrind tool for detecting synchronisation errors in C, C++ and Fortran programs that use the POSIX pthreads threading primitives. Anyone knows an equivalent tool for windows? After googling a bit I haven't found anything... 回答1: For the people that eventually should land there: I've found that: Intel thread checker: should be pretty similar to Hellgrind. 回答2: The only thing of heard of in this area is CHESS, from Microsoft Research. Never used it though. No idea if its

Detect C memory 'leaks' that are freed on exit

元气小坏坏 提交于 2020-01-23 07:07:46
问题 Assume I have a C program (running under Linux) which manipulates many data structures, some complex, several of which can grow and shrink but should not in general grow over time. The program is observed to have a gradually increasing RSS over time (more so than can be explained by memory fragmentation). I want to find what is leaking. Running under valgrind is the obvious suggestion here, but valgrind (with --leak-check=full and --show-reachables=yes ) shows no leak. I believe this to be

Zero bytes lost in Valgrind

安稳与你 提交于 2020-01-23 05:58:15
问题 What does it mean when Valgrind reports o bytes lost, like here: ==27752== 0 bytes in 1 blocks are definitely lost in loss record 2 of 1,532 I suspect it is just an artifact from creative use of malloc , but it is good to be sure (-; EDIT: Of course the real question is whether it can be ignored or it is an effective leak that should be fixed by freeing those buffers. 回答1: Yes, this is a real leak, and it should be fixed. When you malloc(0) , malloc may either give you NULL, or an address

valgrind内存泄露检测工具

你离开我真会死。 提交于 2020-01-22 14:45:34
一、安装 valgrind linux环境首先进入root用户 然后执行下面的命令 tar -jxvf valgrind-3.12.0.tar.bz2 cd valgrind-3.12.0 ./configure make make install valgrind --version 查看valgrind 版本,并且验证是否安装成功 二、查看内存泄漏示例 #include <iostream> using namespace std; int main() { char *p = new char[10]; *p = 'a'; *p++ = 'b'; cout << p << endl; return 0; } g++ -g -o core main.cpp valgrind --leak-check=yes --show-reachable=yes --log-file=a.log ./core valgrind --leak-check=full --show-reachable=yes --log-file=a.log ./shdaily.fcgi "op=search&date=2011-04-14&current=4" --tool=memcheck //使用valgrind的memcheck功能 -show-reachable=yes //是否检测控制范围之外的泄漏

Memory leak with Mat in convertTo-function

可紊 提交于 2020-01-21 20:05:38
问题 I have some trouble with managing memory in my function. Valgrid says I'm having a memory leak after the convert-function. Could it be because of the data is not being properly released? I've tried to use temp-pointers, but my program either crashes or is not working properly. Have someone encountered this problem before? this->images.push_back(new cv::Mat()); //ID cv::threshold(*this->images[MASK], *this->images[ID], 0.0, 1.0, cv::THRESH_BINARY); this->images[ID]->convertTo(*this->images[ID]

Why is this not a memory leak in C++?

强颜欢笑 提交于 2020-01-21 12:21:45
问题 A couple of months ago I asked this question where I asked why there was a memory leak. Apparently, I forgot a virtual destructor. Now I'm struggling to understand why this is not a memory leak: #include <iostream> #include <vector> #include <memory> using namespace std; class Base{ public: explicit Base(double a){ a_ = a; } virtual void fun(){ cout << "Base " << a_ << endl; } protected: double a_; }; class Derived : public Base{ public: Derived(double a, double b): Base(a), b_{b}{ } void fun

How to do Binary instrumentation of syscall brk ? (x86-64 Linux) (maybe valgrind?)

﹥>﹥吖頭↗ 提交于 2020-01-21 10:19:06
问题 I'd like to instrument syscall brk (and other calls but this in first order, it's most important to me) in given binary (preferably on actual syscall/sysenter level (x86-64 and x86) of making sys_brk call). Main goal: A part of sandbox which gives fixed amount of memory to jailed process So, I'd like to get rid of brk system calls (and most preferably others in next order) and simulate memory allocations under fixed limit . Fixed limit is memory space, available to program. (You can think

C: try to assign string literal “abc” to an array of size 3, valgrind detects error

喜欢而已 提交于 2020-01-17 06:44:59
问题 I've been thinking of what will happen if I assign a longer string literal to a char array of smaller size. (I understand that if I use a string literal as an initializer, I would probably leave out the size and let the compiler count the number of chars, or use strlen()+1 as the size. ) I have the following code: #include <stdio.h> int main() { char a[3] = "abc"; // a[2] gives an error of initializer-string for array of chars is too long printf("%s\n", a); printf("%p\n", a); } I expect it to