FAQ Database Discussion Community


How to interpret Valgrind output

c++,memory-leaks,valgrind
Valgrind yields the following message block: 1,065,024 bytes in 66,564 blocks are definitely lost in loss record 21 of 27 at 0x4C2B800: operator new[](unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x40CA21: compute(Parameters&, Array<double>&) [clone .constprop.71] (array.hpp:135) by 0x403E70: main (main.cpp:374) How to read this message? main.cpp line 374 reads: results[index] = compute(parameters,...

Issues with memcheck in C calculator

c,valgrind
I'm writing a Calculator in C from scratch (homework assignment) and have troubles with memory somewhere.. The algorithm works perfectly, but I'm getting a set of Valgrind errors/warnings, e.g.: echo -n "1" | valgrind ./a.out --track-origins=yes ==14261== Conditional jump or move depends on uninitialised value(s) ==14261== at 0x400B9F: create_rpn (main.c:53)...

Trouble solving uninitialised value error given by Valgrind

c,debugging,valgrind
I'm currently writing a test program that parses input from a stream. I won't go into too much detail about this program but I am currently trying to parse alphanumeric characters and then assign them to a temp string, temp[100]. After all valid characters are assigned to temp, I allocate...

How to initialize values in c

c,memory-leaks,valgrind
I started learning C using learncodethehardway book. There is an exercise where its talking about valgrind. And at the end it asks to "fix" the valgrind errors. the program is pretty simple,but whatever I tried, valgrind throws Use of uninitialised value of size Conditional jump or move depends on uninitialised...

Preserving the content in valgrind's log files when using --trace-children and execl()

c,exec,valgrind
I am currently cleaning up an existing codebase, and ran across an issue involving valgrind that I'd like to fix as it causes useful information to go lost. Valgrind is called as such: /usr/bin/valgrind --leak-check=full -v --log-file=./log/valgrind/valgrind-%p.log --trace-children=yes ./myapp arg1 arg2 >&! $logfile The program in question is a server...

Valgrind says about “Invalid write” in fclose()

c++,memory-management,valgrind
I created a stream using fmemopen(). I am closing it with fclose() and freeing the buffer after reading. Valgrind reports about problem at fclose() line: ==9323== Invalid write of size 8 ==9323== at 0x52CAE52: _IO_mem_finish (memstream.c:139) ==9323== by 0x52C6A3E: [email protected]@GLIBC_2.2.5 (iofclose.c:63) ==9323== by 0x400CB6: main (main.cpp:80) ==9323== Address 0xffefffa80 is...

Converting Valgrind XML Output to HTML

html,xml,converter,valgrind
I know there is a possibility to create a valgrind output in xml. But is there a possibility to convert it into html? Cause standard converter has problems with valgrind output convention. Or does anybody have a stylesheet for it?

Invalid free() / delete / delete[] / realloc() error in assignment operator

c++,valgrind,free
I am new to programming and when I am trying to run a program using Valgrind I was getting an error like this. I googled hours to solve this problem. please can you tell me where I am going wrong. Hope there is some mistake near assignment operator. Error: ==5130==...

Uninitialized value reported by valgrind when using std::make_shared and virtual inheritance

c++,valgrind
I have the following (overly simplified) example where valgrind complains about uninitialized memory: struct B { virtual ~B() {} }; struct BB : public virtual B { virtual ~BB() = default; }; struct BBB : public virtual B { virtual ~BBB() {} }; struct X : public virtual B, public...

Is a static pointer marked as possibly lost block bad?

c++,pointers,valgrind
After reading about "possibly lost" block message with Valgrind it seems they are bad. I am getting the error for a static pointer class member. I want to verify there is nothing wrong with our code. I am getting this from Valgrind: ==27986== 76 bytes in 1 blocks are possibly...

error valgrind, but no memory leak

c,valgrind
I got suggestion on solving my problem with malloc, calloc or assigning the children to NULL, but literally nothing I do seems to work. I'm working on this for so long that I can't really wrap my brain around what needs to happen. So some help would be greatly appreciated...

Valgrind on ARMv5

c++,c,arm,valgrind
I'm trying to debug a program on a embedded device. The problem is that it uses ARMv5 and valgrind doesn't support that platform (there are some patches over there but I was not able to make it work). I tried some tools like gdb or memwatch, but it isn't enough...

finding a memory allocation error with omnet++

c++,gdb,std,valgrind,omnet++
I am doing networks simulations under omnet++ & veins(v2.0-rc1), for this purpose I experiment 4 scenarios with 20 repetitions for both one. I am getting some errors (i guess that is a memory allocation error) during the simulations of the 3rd & 4th scenarios wich share a common functionnality (ack)....

valgrind error Invalid read of size 8

c,memory-leaks,malloc,valgrind
So I have valgrind complaining with this error in this function: int getMembersNum(Party party){ assert(party != NULL); int i = 0; while (party->members[i] != NULL && i < party->maxMembersNum) <-- HERE i++; return i; } Party is a pointer to a struct and party->members is of type char**. When initialized...

C - Array of Strings & Mysterious Valgrind Error

c,arrays,string,valgrind
I'm trying to allocate a two-dimensional array of strings, where the last member is always a NULL pointer, i.e. an empty array consists of a single NULL pointer. I keep getting Valgrind errors but I have no idea why. /*Initializes the string array to contain the initial * NULL pointer,...

Valgrind Error when creating an array of linked lists (for Hash Table Chaining)

c,linked-list,valgrind
As an overview, I'm trying to create a battleship-like game in C, where ships are placed on a field. Here is the error I am getting: ==11147== Invalid write of size 8 ==11147== at 0x400786: MakeField (battleship.c:34) ==11147== Address 0x8 is not stack'd, malloc'd or (recently) free'd Here is the...

How to detect “possibly lost” bytes in valgrind when no sufficient data are provided?

c++,memory-leaks,valgrind
I have been digging several days in my 1500 lines of code to find those 15 bytes (possibly lost) to no avail. There are no sufficient data provided by valgrind even though I ran the following command: valgrind --leak-check=full --show-reachable=yes --track-origins=yes --show-below-main=yes ./myapp I get the following block of report:...

Unitialized Heap Allocation Misunderstanding (Code Works — Need to Correct to Remove Valgrind Error)

c,memory-management,malloc,valgrind,char-pointer
My code works fine, but I am receiving valgrind errors. I want to know how to correct my code to in respect to using these malloc and free statements correctly with the char * * dest. Please don't tell me not to malloc and free unless I am doing it...

Valgrind's debugging result doesn't show me the num of rows where the error happens

c++,c,debugging,valgrind
this is Valgrind debugging result: valgrind --leak-check=yes --track-origins=yes ./ns-server ==43648== Memcheck, a memory error detector ==43648== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==43648== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info ==43648== Command: ./ns-server ==43648== --43648-- ./ns-server: --43648-- dSYM directory is missing; consider...

Waiting for system call to finish

c++,linux,valgrind
I've been tasked to create a program that takes a text file that contains a list of programs as input. It then needs to run valgrind on the programs (one at a time) until valgrind ends or until the program hits a max allotted time. I have the program doing...

Invalid read of size 4 on fscanf

c,arrays,valgrind,dynamic-arrays,fscanf
Running my program through valgrind, I'm getting an invalid read of size 4 error in the following code (I think at the line where fscanf is called) Important Info: numIntegers is the maximum number of integers that can be read, while numsInFile specifies the amount of integers present in the...

trying to install valgrind but stuck at make valgrind, how?

c,make,valgrind,gnu-make
This might be a silly question, actually I have just started with it. I am following a tutorial to LCTHW and I am trying to install valgrind, the author specifies steps: 1) Download it (use wget if you don't have curl) curl -O http://valgrind.org/downloads/valgrind-3.6.1.tar.bz2 use md5sum to make sure it...

fprintf valgrind error

c,printf,valgrind
My program sorts the input from a text file and then fprintf it into output file. However valgrind reports some nasty errors for fprintf calls, which I do not understand. Any hints whats the reason for them? #include <stdio.h> #include <stdlib.h> #include <string.h> void * mymalloc (int size) { static...

valgrind error: invalid read

c,memory,memory-management,memory-leaks,valgrind
I am writing following program: int main() { long sLen = 0; char ch, *str = (char *)malloc(sizeof(char)); while((ch = getchar()) != '\n') { str[sLen] = ch; str = (char *)realloc(str, (1 + (sLen++)) * sizeof(char)); } int length = strlen(str); printf("Length of string: %d\n", length); printf("Input string: \"%s\"\n", str);...

cuda-memcheck fails to detect memory leak in an R package

r,memory-leaks,cuda,valgrind
I'm building CUDA-accelerated R packages, and I want to debug with cuda-memcheck. So in this minimal example (in the deliberate_memory_leak GitHub branch), I create a memory leak in someCUDAcode.c by commenting out a necessary call to cudaFree. Then, I see if cuda-memcheck can find the leak. $ cuda-memcheck --leak-check full...

Valgrind and misuse of new[]?

c++,memory-leaks,valgrind
Valgrind is throwing a bunch of errors concerning the new[] operator in my program. I condensed it to a smaller example below #include <iostream> #include <fstream> #include <iomanip> #include <cmath> #include <ctime> #include <cstdlib> #include <omp.h> int num_spline_pts = 90; double *initialize_TriSol_a(); double *initialize_TriSol_b(); int main(int argc, char **argv) {...

Invalid free() / delete / delete[] / realloc(), 4 bytes inside a block of size 16 alloc'd [closed]

c++,memory-management,vector,valgrind
I've written a program using C++. It runs fine until the end, where it vomits: * Error in `./xwd': free(): invalid pointer: 0x00000000017fd774 * My first thought was that I was doing something wrong in the destructor, but as the relevant class has no destructor as it doesn't use "new",...

Does wprintf cause “conditional jump or move depends on uninitialised value(s)” in valgrind?

c,valgrind
I'm trying to code the function solving the following problem (which is irrellevant, I'm describing it in order to describe the code that follows): Given a word and a rule in form: "lhs->rhs" where word = lhs ^ suffix, output rhs ^ suffix, so for example: If a word is...

std::ifstream read reading wrong size for large numbers

c++,segmentation-fault,valgrind,ifstream
I have a Problem while reading a lare chunk of binary data from a file at once. Reading the same amount of bytes bytewise is working. I have to following sample code: std::ifstream inFile; inFile.open("example.bin", std::ios::binary | std::ios::in); uint32_t bytesToAllocate = static_cast<uint32_t>(this->sectionLength)-4; this->binaryData = new uint8_t[bytesToAllocate]; inFile.read(reinterpret_cast<char*>(&this->binaryData), bytesToAllocate); if i...

Valgrind changes working directory with CTest in KDevelop

c++,cmake,valgrind,ctest
I am starting a test with Helgrind using Ctest: find_program(VALGRIND_EXECUTABLE valgrind) message(STATUS "Valgrind in ${VALGRIND_EXECUTABLE}") configure_file(project.supp project.supp) set(BOOST_TEST_ARGS --catch_system_errors=no) set(VALGRIND_HELGRIND_OPTIONS --tool=helgrind --suppressions=${CMAKE_CURRENT_BINARY_DIR}/project.supp --xml=yes --read-var-info=yes) add_test(NAME TestHelgrind COMMAND ${VALGRIND_EXECUTABLE} ${VALGRIND_HELGRIND_OPTIONS} --xml-file=${CMAKE_CURRENT_BINARY_DIR}/test.xml...

Global struct memory error

c,struct,heap,valgrind
My program's reading from config file using libconfig and saving values to the global struct. It's working fine but valgrind says there's error. And the error only shows for char pointer variable. What is that error and how to fix that ? Thank you #include <stdio.h> #include <libconfig.h> #include "stdlib.h"...

C - Error is “free(): invalid next size (normal) ”

pointers,gdb,valgrind,sigabrt
I just can not find what is causing this problem. MYSQL *startup(unsigned char *path_to_file, int size_of_path) { MYSQL *con; bool path_is_file = false; bool path_is_directory = false; FILE *startup_file; int i; unsigned char buffer[LINEBUFFERSIZE]; unsigned char string[LINEBUFFERSIZE]; unsigned char c; //Allocate memory for the new file path unsigned char *path;...

Valgrind errors, Invalid read of size & conditional jump or move depens on uninitialised value

c,valgrind
I've got those two errors and could need some help to find a solution after searching for a long time: ==4902== 1 errors in context 1 of 2: ==4902== Invalid read of size 1 ==4902== at 0x4010A0: getData (main.c:321) ==4902== by 0x402527: main (main.c:783) ==4902== Address 0x52007af is 1 bytes...

Char* Array Memory Leak

c++,arrays,memory-leaks,valgrind,dynamic-memory-allocation
I am having issues de-allocating memory that I used in my char* array. In my code snippet below, I am creating a char* array named input that holds pointers to single words at a time followed by a pointerNULL at the end of the array. This is the only time...

Unable to suppress errors in valgrind

c++,linux,valgrind
Can someone please show me an example of how to add custom suppressions to valgrind? I am 99.99% sure it generates an error for the string class and I want to suppress the errors in a .supp file. I thought it would be simple enough just adding it to the...

new libstdc++ of gcc5.1 may allocate large heap memory

c++,c,gcc,valgrind
valgrind detects "still reachable leak" in an empty program compiled with gcc5.1, g++ ./a.cpp, int main () {} valgrind says, valgrind ./a.out, ==32037== HEAP SUMMARY: ==32037== in use at exit: 72,704 bytes in 1 blocks ==32037== total heap usage: 1 allocs, 0 frees, 72,704 bytes allocated ==32037== ==32037== LEAK SUMMARY:...

Creating shared_ptr seems to cause segfault

c++,segmentation-fault,gdb,valgrind
I have the following function static node_ptr make_node_ptr() { return node_ptr(new node()); } where using node_ptr = std::shared_ptr<node>; I tried to find my segmentation fault with valgrind and gdb. In both I get more or less the same stack trace. Program received signal SIGSEGV, Segmentation fault. 0x00007fff8f5d7e82 in szone_malloc_should_clear ()...

BIO_dump_fp causing hundreds of valgrind errors

c++,memory-leaks,openssl,valgrind
I'm trying to use the OpenSSL library for AES encryption. Everything compiles and seems to work fine. However, when I use BIO_dump_fp(stdout, (char*)ciphertext, ciphertext_len) valgrind ends up reporting hundreds of errors, mostly "conditional jump of move depends on uninitialized value(s)" errors, like this one: Conditional jump or move depends on...

Cannot find the memory leak. Staring for 1 hour

c,pointers,memory,memory-leaks,valgrind
Following C code has memory leak. I'm staring it for one hour but can't find it. I've been able to narrow it down to that function but still no luck for improvement. Can you help me to find it? Any help is appreciated. Thank you! void insert ( LISTNODEPTR *sPtr,...

C - memory leak in case of big input [closed]

c,memory-leaks,valgrind
For an assignment, I have to order a list of students. Each one is represented by a number (string of size 15), his father's lastname (string 20), his mother's lastname (string 20) and his firstname (string 20 also). I did a program that build from a file the list of...

Why is there an Invalid Write here (Valgrind)

c,valgrind
I am coding a shell. When I execute it like this cat /dev/urandom | valgrind ./myshell to run some test and see if I don't have any segfault or other errors, valgrind sometimes tell me that I have an Invalid Write in function my_wordcpy at this line tab[++j] = str[*i];...

Valgrind error conditional jump

c,valgrind
I'm writing a program that loads input until a specific word is typed in,in this case its word "konec".Although my program seems to work just about ok,I can't solve this Valgrind error ==16573== Memcheck, a memory error detector ==16573== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al....

Valgrind Error Struct

c,valgrind
I'm trying to write and read a simple struct node in a juantest.txt file. But I get the follow error when I verify this code using valgrind. Could you help to fix this please? What happend here?. ==25771== 4 errors in context 99 of 100: ==25771== Invalid read of size...

How to make Valgrind log all allocations?

c++,c,valgrind
I'd like to make Valgrind log the allocations even when no memory errors were found. How can this be done?

Possible leak from exception?

c++,memory-leaks,valgrind
Why would valgrind say that this is possibly leaking. #include <stdexcept> int main(int argc, char const *argv[]) { throw std::runtime_error(""); return 0; } With valgrind saying (updated with full check) ==26803== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info ==26803== Command: ./test ==26803== terminate called after throwing an...

To allocate or not to allocate. Invalid read of size 1 errors. [Staring for 2 hours]

c,memory-leaks,valgrind
This is the code I'm working on code However there are problems. Some or all might be because of not allocating space for data in nodes (line 135~) because the line is changing during iteration in main. But when I allocate space for it, at line 135, the outcome doesn't...

Linux/C: how to trace the accesses on a number of variables

linux,gdb,valgrind,trace
I'm trying to profile some existing C code that uses large structs with many members, with the goal of refactoring it into a smaller cache-friendly core struct containing the most frequently-accessed members and a pointer to the colder data. I want to come up with a way of monitoring the...

Valgrind getting strange error

c++,valgrind
Hi why I am getting this strange Valgrind error ==18572== Memcheck, a memory error detector ==18572== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==18572== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info ==18572== Command: ./test ==18572== ==18572== Syscall param open(filename) points to unaddressable byte(s)...

Valgrind: Memory still reachable with trivial program using

c++,valgrind
Take the following trivial program: #include <iostream> int main() { return 0; } If I run this using valgrind, I'm told that there are 72,704 bytes in 1 blocks that are still reachable. There have been extensive discussions on SO about whether or not to worry about still reachable warnings--I'm...

How to redirect the output of the program Valgrind is running on?

bash,valgrind
Background of the question: I run a command like this: $ valgrind ./my_program < 1.in And I get Valgrind's messages about leaks and errors as well as the output stdout and stderr streams of the my_program. Question: I would like to redirect/mute all the streams of my_program (both stdout and...

Permutations with Repetitions in C; Valgrind Errors

c,valgrind
I'm trying to write a program where essentially I am trying to figure out the combination of a combination lock. I take in two inputs from the user, the number of dials to be turned (which I've called max indices) and the highest number each dial can go to (which...

Valgrind memcheck finds lots of conditional jumps and invalid reads in commercial library

c,valgrind
I am debugging a program which links against a commercial API library (under Linux). I am using valgrind memcheck, because I am experiencing strange behavior which could be due to writes beyond allocated blocks of memory: valgrind --tool=memcheck --error-limit=no --log-file=memcheck.log ./executable The first thing which jumps to my eye, however,...

Limit number of std::string allocations

c++,valgrind,allocation,stdstring
I have a function that constructs a std::string from a const char* with two numbers, passed as parameters, appended to the end of it. std::string makeName(const char* name, uint16_t num1, uint16_t num2) { std::string new_name(name); new_name.reserve(new_name.length()+5); new_name += ":"; new_name += boost::lexical_cast<std::string>(num1); new_name += ":"; new_name += boost::lexical_cast<std::string>(num2); return new_name;...

Valgrind won't detect buffer overflow

c,valgrind,buffer-overflow
#include <stdio.h> main() { char buf[8]; sprintf(buf,"AAAA%3s","XXssssssssXXXsssssXXX"); printf("%s\n",buf); } I expected valgrind to detect a buffer overflow with the above code. But it does not report any errors or warnings. Do I need to enable any special flags for that?...

C++ Templates specialisation char* and Valgrind

c++,templates,memory-leaks,char,valgrind
I've got a huge problem with memory leaks in my program. I use Valgrind to check memory leaks and with some changes I got about ~20 errors or ~40 errors, but still I can't eliminate all and don't know how. And I can't change the code in main function, I...

valgrind improper output location

c++,ubuntu,valgrind
I have a program that is supposed to run valgind on another program and direct the valgrind output to another file. The code I'm using is: char* args[] = {"sudo", //(This is inside a fork) "valgrind", "--leak-check=full", "--show-leak-kinds=definite", "--errors-for-leak-kinds=definite", "<path to executable>", //placeholders "&><path to output file>", //placeholders "\0"}; execvp("sudo",args);...

mongoc_init() and mongoc_cleanup() may make memory “still reachable”

mongodb,valgrind,mongo-c-driver
I have a class to do mongodb operation using mongodb-c-driver. In the constructor, mongoc_init() is called. In deconstructor, mongoc_cleanup() is called. Then, valgrind 3.10.1 told me that some memory "still reachable". Part of the valgrind output is following: ==23222== 16,384 bytes in 1 blocks are still reachable in loss record...

How do I trace “fate” of a particular value?

c,gdb,valgrind,trace
I see some value in some place, but unsure where it has originated in my program. How do I figure out where this value initially comes from? I expect the following event types to be logged: A value originated from constant, arithmetical expression or syscall - the initial event; The...

How to tell valgrind to ignore SIGSEGV

jni,valgrind,sigsegv
I have a C++/JNI program that runs fine standalone but exits with SIGSEGV when run with valgrind. I've verified that the signal is thrown from the exact same spot as when running the program in the gdb debugger. In the context of gdb the issue is well explained here: Strange...

Conditional jump or move depends on uninitialised value(s) using realloc

c,valgrind
I wrote a simple echo-server in c that writes back all clients besides the one that wrote (using realloc) , I get errors in valgrind and I'm not sure what I'm doing wrong. I would like to get some help. here is my code: int read_from_socket(int connfd,char **usr_str); int main...