Category : memory-leaks

int* integer = new int{10}; cout << *integer << endl; free(integer); cout << *integer << endl; Output: 10 0 According to the code I’ve tested on my machine, It’s quite obvious that the allocated memory is being successfully deallocated by using free() But there are articles on the internet that discourages the use of the ..

Read more

Let’s say I have the following classes: Base.hpp: class Derived; class Base { protected: Derived *boss; //other things public: Base(); constuctor with irrellevant parameters virtual ~Base(); // after confirmation from the comments, //I made the destructor virtual but I still experience crashes due to segmentation fault // other things }; Base.cpp: Base::Base() {}//irrelevant Base::~Base() { ..

Read more

This school project I’m working on requires writing a full application without libraries (two exceptions being std::ostream::operator<< for overriding << operator to write out stringstreams and std::exception to implement our own exceptions). For grading, the program is compiled on a Linux server which students have access to, and the computer I use to run and ..

Read more

When I alternate between 2 OpenMP parallel regions with a different number of threads repeatedly, the memory consumption increases indefinitely (tens of MB or even more). And it does this even in such a simple code snippet: #include <unistd.h> int main() { while (true) { #pragma omp parallel num_threads(16) usleep(30); #pragma omp parallel num_threads(8) usleep(30); ..

Read more

I am running valgrind like this: valgrind –leak-check=full –show-leak-kinds=all –track-origins=yes ./smash < test_input1.txt and the output is: ==16692== Invalid read of size 4 ==16692== at 0x10CD50: ForegroundCommand::execute() (in /home) How can I request it to show which line caused the problem in ForegroundCommand::execute()? Update: I added -g and still same output my makefile: COMPILER := ..

Read more