valgrind

Leaking memory with pthreads

怎甘沉沦 提交于 2019-12-01 21:35:00
I'm using pthreads and according to valgrind I am leaking memory, like in valgrind memory leak errors when using pthread_create The top answer says that if you pthread_join all the threads this memory will be reclaimed, but it isn't for me. 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 output ==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 bytes

std::thread.join() SIGSEGV on Mac OS under Valgrind

荒凉一梦 提交于 2019-12-01 21:17:06
问题 The following simple code (C++ 11) will run just find on Mac OS and Linux: #include <thread> #include <chrono> #include <iostream> void threadFunction() { for (int cc=0; cc < 10000000; ++cc) { if (cc%1000000 == 0) { std::this_thread::sleep_for(std::chrono::milliseconds(200)); } } } int main(int argc, char **argv) { std::thread threads[10]; for (int tt = 0; tt < 10; ++tt) { threads[tt] = std::thread(threadFunction); } // Wait for the threads to complete for (int tt = 0; tt < 10; ++tt) { printf

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

匆匆过客 提交于 2019-12-01 21:06:07
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() override{ cout << "Derived " << a_ << endl; } private: double b_; }; int main() { vector<unique_ptr

valgrind: mmap(0x600000, 8192) failed in UME with error 12 (Cannot allocate memory)

随声附和 提交于 2019-12-01 19:50:39
I was following this exercise . This page has instructions to install Valgrind 3.6.1 but this version of Valgrind is not supported by my current Linux kernel version. So, I installed Valgrind 3.11.0 and followed the instructions there after and on running this command: $ valgrind ./ex4 got this error: valgrind: mmap(0x600000, 8192) failed in UME with error 12 (Cannot allocate memory). How to do I fix it? I'm using Ubuntu 14.04 LTS with kernel version 4.4.0 The error which you have encountered is actually a kernel bug, which was fixed in the subsequent versions. More details here: https:/

valgrind: mmap(0x600000, 8192) failed in UME with error 12 (Cannot allocate memory)

♀尐吖头ヾ 提交于 2019-12-01 19:13:54
问题 I was following this exercise. This page has instructions to install Valgrind 3.6.1 but this version of Valgrind is not supported by my current Linux kernel version. So, I installed Valgrind 3.11.0 and followed the instructions there after and on running this command: $ valgrind ./ex4 got this error: valgrind: mmap(0x600000, 8192) failed in UME with error 12 (Cannot allocate memory). How to do I fix it? I'm using Ubuntu 14.04 LTS with kernel version 4.4.0 回答1: The error which you have

std::thread.join() SIGSEGV on Mac OS under Valgrind

耗尽温柔 提交于 2019-12-01 18:44:12
The following simple code (C++ 11) will run just find on Mac OS and Linux: #include <thread> #include <chrono> #include <iostream> void threadFunction() { for (int cc=0; cc < 10000000; ++cc) { if (cc%1000000 == 0) { std::this_thread::sleep_for(std::chrono::milliseconds(200)); } } } int main(int argc, char **argv) { std::thread threads[10]; for (int tt = 0; tt < 10; ++tt) { threads[tt] = std::thread(threadFunction); } // Wait for the threads to complete for (int tt = 0; tt < 10; ++tt) { printf("About to join %d\n", tt); std::cout.flush(); threads[tt].join(); printf("Joined %d\n", tt); std::cout

Still reachable in valgrind

删除回忆录丶 提交于 2019-12-01 16:57:00
问题 While searching about still reachable in valgrind, some people say its not a problem. we don't nedd to fix it. Some people say it needs to be fixed.I would be better if somebody could exaplain me explicitly what is the logic behind this still reachable. Is it mandatory to fix this? [EDIT] I have following valgrind output for my C program.Do i need to fix it? LEAK SUMMARY: ==27333== definitely lost: 0 bytes in 0 blocks. ==27333== possibly lost: 0 bytes in 0 blocks. ==27333== still reachable:

How to make Valgrind log all allocations?

二次信任 提交于 2019-12-01 16:33:29
问题 I'd like to make Valgrind log the allocations even when no memory errors were found. How can this be done? 回答1: You would use Massif for that (a valgrind tool). The manual link is easy enough to follow, but for future reference, here's how to use it, straight out of the manual: valgrind --tool=massif prog This will produce a file that you can analyze with ms_print . The filename will be massif.out.<numbers> . Just use ms_print to get a nice output: ms_print massif.out.12345 What you're

enabling no memory management in gcc

南楼画角 提交于 2019-12-01 14:29:01
Is there any option for enabling no memory management in gcc while compiling? Main points on using Valgrind while debugging C code compiled with GCC: Compile your code using -O0. In some relatively rare cases (e.g. inline assembly) you may need -O1. Never use higher optimisation levels. The compiler will mangle your code so much that it can make your life impossible. Variables can disappear completely, functions can go mysteriously away as they get inlined, loops become unrolled and so on. Basically with anything other than -O0 you run the risk that the executable code will bear little

enabling no memory management in gcc

家住魔仙堡 提交于 2019-12-01 13:29:16
问题 Is there any option for enabling no memory management in gcc while compiling? 回答1: Main points on using Valgrind while debugging C code compiled with GCC: Compile your code using -O0. In some relatively rare cases (e.g. inline assembly) you may need -O1. Never use higher optimisation levels. The compiler will mangle your code so much that it can make your life impossible. Variables can disappear completely, functions can go mysteriously away as they get inlined, loops become unrolled and so