User Leak, libc++ leak or false positive - c++

I am building a dynamic library on mac in C++11 using the clang compiler and libc++ standard library. When I run valgrind on my test code which links to my dynamic library I get one block of memory that is definitely lost. Here is the valgrind report:
==45659== 36 bytes in 1 blocks are definitely lost in loss record 57 of 228
==45659== at 0x66BB: malloc (vg_replace_malloc.c:300)
==45659== by 0x31EAB0: __Balloc_D2A (in /usr/lib/system/libsystem_c.dylib)
==45659== by 0x31F2A5: __d2b_D2A (in /usr/lib/system/libsystem_c.dylib)
==45659== by 0x31BED6: __dtoa (in /usr/lib/system/libsystem_c.dylib)
==45659== by 0x3438A9: __vfprintf (in /usr/lib/system/libsystem_c.dylib)
==45659== by 0x36A2DA: __v2printf (in /usr/lib/system/libsystem_c.dylib)
==45659== by 0x34FF66: _vsnprintf (in /usr/lib/system/libsystem_c.dylib)
==45659== by 0x34FFC5: vsnprintf_l (in /usr/lib/system/libsystem_c.dylib)
==45659== by 0x34057A: snprintf_l (in /usr/lib/system/libsystem_c.dylib)
==45659== by 0x10C75A: std::__1::num_put<char, std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > >::do_put(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, std::__1::ios_base&, char, double) const (in /usr/lib/libc++.1.dylib)
==45659== by 0xF3221: std::__1::basic_ostream<char, std::__1::char_traits<char> >::operator<<(double) (in /usr/lib/libc++.1.dylib)
==45659== by 0x12102: lmpsdata::header_data::write_dimension(std::__1::basic_ofstream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (header_data.cpp:75)
==45659==
==45659== LEAK SUMMARY:
==45659== definitely lost: 36 bytes in 1 blocks
==45659== indirectly lost: 0 bytes in 0 blocks
==45659== possibly lost: 0 bytes in 0 blocks
==45659== still reachable: 18,340 bytes in 215 blocks
==45659== suppressed: 25,274 bytes in 374 blocks
That particular section of code does not deal with any memory I have dynamically allocated, only STL objects and streams are used. I have attached both the header file and the method reported by valgrind as causing the leak. Can someone please explain what is going on here? I am absolutely baffled.
header_data.h
#ifndef ____header_data__
#define ____header_data__
#include <string>
#include <fstream>
#include <cstdint>
#include <vector>
#include <map>
namespace lmpsdata {
class header_data
{//LAMMPS header information
//only the point particle header information has been implemented
//since the current atom base class is designed for point particles only
public:
header_data():xdim(2), ydim(2), zdim(2), tiltdim(3) {}
//methods
void read(const std::string &, const std::string &);
void write(std::ofstream &, const std::string &); //this write command will replace the one
std::string check_header_keyword(const std::string &, bool &);
uint64_t get(const std::string&);
std::vector<double>& get_vector(const std::string&);
void set(const std::string&, uint64_t);
void set_vector(const std::string&, std::vector<double>&);
private:
//methods
void read_dimension(const std::string&, const std::string&);
void write_dimension(std::ofstream&, const std::string&);
//members
uint64_t atomnum;
uint64_t bondnum;
uint64_t anglenum;
uint64_t dihedralnum;
uint64_t impropernum;
uint64_t atomtypenum;
uint64_t bondtypenum;
uint64_t angletypenum;
uint64_t dihedraltypenum;
uint64_t impropertypenum;
uint64_t extrabondnum;
std::vector<double> xdim;
std::vector<double> ydim;
std::vector<double> zdim;
std::vector<double> tiltdim;//for use with triclinic system
std::map<std::string, uint64_t&> int_map {
{"atoms", atomnum},
{"bonds", bondnum},
{"angles", anglenum},
{"dihedrals", dihedralnum},
{"impropers", impropernum},
{"atom types", atomtypenum},
{"bond types", bondtypenum},
{"angle types", angletypenum},
{"dihedral types", dihedraltypenum},
{"improper types", impropertypenum},
{"extra bond per atom", extrabondnum},
};
std::map<std::string, std::vector<double>&> v_map {
{"xlo xhi", xdim},
{"ylo yhi", ydim},
{"zlo zhi", zdim},
{"xy xz yz", tiltdim}
};
};
}
#endif /* defined(____header_data__) */
lmpsdata.cpp only write_dimension method and beginning of file is shown
#include "header_data.h"
#include <stdexcept>
using namespace lmpsdata;
void header_data::write_dimension(std::ofstream &file, const std::string& keyword)
{
std::vector<double>& data = v_map.at(keyword);
for (auto value: data) {
file << value << " ";
}
}
If more information is needed please let me know.

You have not mentioned the exact versions of OSX and valgrind that you're using. I've not been able to entirely reproduce this on the version that I'm using (OSX 10.10; valgrind HEAD==Valgrind-3.11.0.SVN).
This is not in the C++ standard library, but in the C library. You should be able to reproduce it (almost identically) with the simple code:
#include <stdio.h>
#include <xlocale.h>
int
main(int argc, char **argv)
{
locale_t loc = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0);
double d = 22.22;
char buffer[1024];
snprintf_l(buffer, 1024, loc, "%f\n", d);
printf("%s", buffer);
freelocale(loc);
}
When run with valgrind --show-leak-kinds=all --leak-check=full ./leak I see some 'still reachable' leaks (yours should show actual leaks in this case):
==26151== 32 bytes in 1 blocks are still reachable in loss record 28 of 85
==26151== at 0x10000850B: malloc (in /usr/local/Cellar/valgrind/HEAD/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==26151== by 0x1002BC7DF: __Balloc_D2A (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002B9533: __rv_alloc_D2A (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002B9B3A: __dtoa (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002E1D52: __vfprintf (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x10030A9AE: __v2printf (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002EF154: _vsnprintf (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002EF1B3: vsnprintf_l (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002DF5F7: snprintf_l (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x100000ECA: main (leak.cpp:10)
==26151==
==26151== 36 bytes in 1 blocks are still reachable in loss record 30 of 85
==26151== at 0x10000850B: malloc (in /usr/local/Cellar/valgrind/HEAD/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==26151== by 0x1002BC7DF: __Balloc_D2A (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002BD055: __d2b_D2A (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002B986B: __dtoa (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002E1D52: __vfprintf (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x10030A9AE: __v2printf (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002EF154: _vsnprintf (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002EF1B3: vsnprintf_l (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002DF5F7: snprintf_l (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x100000ECA: main (leak.cpp:10)
==26151==
==26151== 80 bytes in 1 blocks are still reachable in loss record 47 of 85
==26151== at 0x10000850B: malloc (in /usr/local/Cellar/valgrind/HEAD/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==26151== by 0x1002BC736: __Balloc_D2A (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002BD055: __d2b_D2A (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002B986B: __dtoa (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002E1D52: __vfprintf (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x10030A9AE: __v2printf (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002EF154: _vsnprintf (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002EF1B3: vsnprintf_l (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x1002DF5F7: snprintf_l (in /usr/lib/system/libsystem_c.dylib)
==26151== by 0x100000ECA: main (leak.cpp:10)
I'd put in a suppression for it, as it's almost undoubtably not a real leak and is completely out of your control.
looking at the published OSX libc source, I can't see where the bug is present - 320 and later all look OK; with the underlying code appearing to allocate and free where necessary. The bug may have been introduced and fixed, though, as I didn't perform an exhaustive trawl of all the sources; the file in question is vfprintf.c, you're looking at the dtoaresult assignments & frees.
To determine your version of libc, you can do:
$ otool -l /usr/lib/system/libsystem_c.dylib | grep -A5 ID_
On my system I get the output:
cmd LC_ID_DYLIB
cmdsize 64
name /usr/lib/system/libsystem_c.dylib (offset 24)
time stamp 1 Thu Jan 1 01:00:01 1970
current version 1044.10.1
compatibility version 1.0.0
997, I think, is mavericks (10.9). I don't know if they introduced a leak in the code at some point in the mavericks timeframe and then fixed it - there doesn't appear to be a code path in the __vfprintf routine that actually leaks in any of the published source.

Related

std::thread causes segmentation fault in Raspbian using gcc-linaro-4.9.4

I'm getting a segmentation fault on code that looks perfectly valid to me.
Here's a minimal recreating example:
#include <iostream>
#include <thread>
void func()
{
/* do nothing; thread contents are irrelevant */
}
int main()
{
for (unsigned idx = 0; idx < 1000; idx++)
{
std::thread t(func);
void* buffer = malloc(1000);
free(buffer);
t.join();
}
return 0;
}
I made a run with prints, to check which iteration fails; I got the segmentation fault on iteration #292.
I used gcc-linaro-4.9.4 (taken from here: https://releases.linaro.org/components/toolchain/binaries/4.9-2017.01/arm-linux-gnueabihf/).
I compiled the program this way:
arm-linux-gnueabihf-g++ -std=c++11 -std=gnu++11 -lpthread -pthread main.cpp -o main.out
I tried recreating this in gcc-linaro-6.5, and didn't have the problem there.
Any idea why this happens?
Edit 1
There is no warnings/errors when I compile this code.
Running it under strace reveals nothing special.
Running it under GDB reveals that the segmentation faults happens in free function:
Thread 1 "main.out" received signal SIGSEGV, Segmentation fault.
_int_free (av=0x76d84794 <main_arena>, p=0x1e8bf, have_lock=0) at malloc.c:4043
4043 malloc.c: No such file or directory.
(gdb) bt
#0 _int_free (av=0x76d84794 <main_arena>, p=0x1e8bf, have_lock=0) at malloc.c:4043
#1 0x00010bfa in main ()
Running it under valgrind reveals the following:
==361== Thread 2:
==361== Invalid read of size 4
==361== at 0x4951D64: ??? (in /usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.22)
==361== Address 0x4becf74 is 0 bytes after a block of size 28 alloc'd
==361== at 0x4847D4C: operator new(unsigned int) (vg_replace_malloc.c:328)
==361== by 0x11629: __gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<void (*())()> >, std::allocator<std::thread::_Impl<std::_Bind_simple<void (*())()> > >, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned int, void const*) (in /home/pi/main.out)
==361==
==361== Invalid write of size 4
==361== at 0x4951D6C: ??? (in /usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.22)
==361== Address 0x4becf74 is 0 bytes after a block of size 28 alloc'd
==361== at 0x4847D4C: operator new(unsigned int) (vg_replace_malloc.c:328)
==361== by 0x11629: __gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<void (*())()> >, std::allocator<std::thread::_Impl<std::_Bind_simple<void (*())()> > >, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned int, void const*) (in /home/pi/main.out)
==361==
==361==
==361== HEAP SUMMARY:
==361== in use at exit: 28,000 bytes in 1,000 blocks
==361== total heap usage: 2,002 allocs, 1,002 frees, 1,048,368 bytes allocated
==361==
==361== Thread 1:
==361== 28,000 bytes in 1,000 blocks are definitely lost in loss record 1 of 1
==361== at 0x4847D4C: operator new(unsigned int) (vg_replace_malloc.c:328)
==361== by 0x11629: __gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<std::thread::_Impl<std::_Bind_simple<void (*())()> >, std::allocator<std::thread::_Impl<std::_Bind_simple<void (*())()> > >, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned int, void const*) (in /home/pi/main.out)
==361==
==361== LEAK SUMMARY:
==361== definitely lost: 28,000 bytes in 1,000 blocks
==361== indirectly lost: 0 bytes in 0 blocks
==361== possibly lost: 0 bytes in 0 blocks
==361== still reachable: 0 bytes in 0 blocks
==361== suppressed: 0 bytes in 0 blocks
==361==
==361== For counts of detected and suppressed errors, rerun with: -v
==361== ERROR SUMMARY: 2017 errors from 3 contexts (suppressed: 6 from 3)
edit 2
I still get segmetation fault after I remove the -lpthread and -std=c++11 compilation flags. This is the way I compiled it this time:
arm-linux-gnueabihf-g++ -std=gnu++11 -pthread main.cpp -o main.out
I think the problem is a mismatch between your code and the libstdc++.so library you're linking to.
One possibility is that the wrong libstdc++.so is being used at runtime, which you could check by using the ldd utility. The correct version for GCC 4.9.4 is libstdc++.so.6.0.20 so if you see it linking to a different version, that's a problem.
The second possibility is that it's the right libstdc++.so but it is compiled with different settings from your code, and so the std::thread in your code uses atomic operations for shared_ptr reference counting, but the std::thread in the library uses a mutex (which is the same problem as described in GCC Bug 42734). If the crash and the valgrind errors go away when you compile your program with -march=armv5t then it would confirm this is the problem.

Cannot find memory leak detected by Valgrind

I'm running and analyzing with Valgrind this code:
int main() {
Set<int> c;
return 0;
}
So the output is:
jscherman#jscherman:~/ClionProjects/algo2-t3-bts$ g++ set.hpp tests.cpp && valgrind --leak-check=yes --show-leak-kinds=all ./a.out
==3528== Memcheck, a memory error detector
==3528== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==3528== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==3528== Command: ./a.out
==3528==
test_mleak...ok
==3528==
==3528== HEAP SUMMARY:
==3528== in use at exit: 72,704 bytes in 1 blocks
==3528== total heap usage: 2 allocs, 1 frees, 73,728 bytes allocated
==3528==
==3528== 72,704 bytes in 1 blocks are still reachable in loss record 1 of 1
==3528== at 0x4C2DC10: malloc (vg_replace_malloc.c:299)
==3528== by 0x4EC3EFF: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
==3528== by 0x40104E9: call_init.part.0 (dl-init.c:72)
==3528== by 0x40105FA: call_init (dl-init.c:30)
==3528== by 0x40105FA: _dl_init (dl-init.c:120)
==3528== by 0x4000CF9: ??? (in /lib/x86_64-linux-gnu/ld-2.23.so)
==3528==
==3528== LEAK SUMMARY:
==3528== definitely lost: 0 bytes in 0 blocks
==3528== indirectly lost: 0 bytes in 0 blocks
==3528== possibly lost: 0 bytes in 0 blocks
==3528== still reachable: 72,704 bytes in 1 blocks
==3528== suppressed: 0 bytes in 0 blocks
==3528==
==3528== For counts of detected and suppressed errors, rerun with: -v
==3528== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
Apparently, i'm loosing memory at the constructor of Set, but i can't find the actual reason. This is how i implemented Set (in a BTS):
template<class T>
class Set {
public:
Set() : root_(NULL), cardinal_(0) {}
~Set() {delete root_;}
void insert(const T &);
bool belongs(const T &) const;
void remove(const T &);
const T &min() const;
const T &max() const;
unsigned int cardinal() const;
private:
struct Node {
Node(const T &v) : value(v), left(NULL), right(NULL) {}
~Node() {delete right; delete left;}
T value;
Node *left;
Node *right;
};
Node *root_;
int cardinal_;
}
Any idea how to solve this leak? Thanks!
You're not leaking anything--you're just misunderstanding what valgrind is telling you.
It thinks there may be some problem underneath _dl_init(), but this is a red herring. You can safely add it to your valgrind suppressions file (which is always a good thing to have, so you aren't bothered by false alarms from system libraries).

Segmentation fault issue during creation new thread using activemq-cpp library

My environment is opensuse, gcc5, clion, active-mq 3.10.0.
Am my missing something? I got Segmentation fault after launch program.
class MyTask : public CompositeTask{
public:
MyTask() { }
public:
virtual bool isPending() const override {
cout<<"MyTask()::isPending\n";
return true;
}
virtual bool iterate() override {
cout<<"MyTask()::iterate\n";
return false;
}
};
class RR{
CompositeTaskRunner compositeTaskRunner;
public:
RR(){
CompositeTask* m = new MyTask();
compositeTaskRunner.addTask(m);
}
void start(){
compositeTaskRunner.start();
}
};
main(){
RR* runner = new RR();
runner->start();
}
output from valgrind
==12202== Memcheck, a memory error detector
==12202== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==12202== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==12202== Command: ./CppMicroServicesExampleDriver
==12202== Parent PID: 9602
==12202==
==12202== Invalid read of size 8
==12202== at 0x5BDCD29: createThreadInstance (Threading.cpp:365)
==12202== by 0x5BDCD29: decaf::internal::util::concurrent::Threading::createNewThread(decaf::lang::Thread*, char const*, long long) (Threading.cpp:920)
==12202== by 0x5C21BB3: decaf::lang::Thread::initializeSelf(decaf::lang::Runnable*, std::string const&, long long) (Thread.cpp:123)
==12202== by 0x5C21F7A: decaf::lang::Thread::Thread(decaf::lang::Runnable*, std::string const&) (Thread.cpp:102)
==12202== by 0x5A5AC36: activemq::threads::CompositeTaskRunner::CompositeTaskRunner() (CompositeTaskRunner.cpp:70)
==12202== by 0x40F5E1: RR::RR() (nano.hpp:32)
==12202== by 0x40BEAD: main (main.cpp:56)
==12202== Address 0x60 is not stack'd, malloc'd or (recently) free'd
==12202==
==12202==
==12202== Process terminating with default action of signal 11 (SIGSEGV)
==12202== Access not within mapped region at address 0x60
==12202== at 0x5BDCD29: createThreadInstance (Threading.cpp:365)
==12202== by 0x5BDCD29: decaf::internal::util::concurrent::Threading::createNewThread(decaf::lang::Thread*, char const*, long long) (Threading.cpp:920)
==12202== by 0x5C21BB3: decaf::lang::Thread::initializeSelf(decaf::lang::Runnable*, std::string const&, long long) (Thread.cpp:123)
==12202== by 0x5C21F7A: decaf::lang::Thread::Thread(decaf::lang::Runnable*, std::string const&) (Thread.cpp:102)
==12202== by 0x5A5AC36: activemq::threads::CompositeTaskRunner::CompositeTaskRunner() (CompositeTaskRunner.cpp:70)
==12202== by 0x40F5E1: RR::RR() (nano.hpp:32)
==12202== by 0x40BEAD: main (main.cpp:56)
==12202== If you believe this happened as a result of a stack
==12202== overflow in your program's main thread (unlikely but
==12202== possible), you can try to increase the size of the
==12202== main thread stack using the --main-stacksize= flag.
==12202== The main thread stack size used in this run was 8388608.
==12202==
==12202== HEAP SUMMARY:
==12202== in use at exit: 126,122 bytes in 577 blocks
==12202== total heap usage: 1,031 allocs, 454 frees, 152,249 bytes allocated
==12202==
==12202== LEAK SUMMARY:
==12202== definitely lost: 0 bytes in 0 blocks
==12202== indirectly lost: 0 bytes in 0 blocks
==12202== possibly lost: 0 bytes in 0 blocks
==12202== still reachable: 126,122 bytes in 577 blocks
==12202== of which reachable via heuristic:
==12202== stdstring : 15,204 bytes in 453 blocks
==12202== suppressed: 0 bytes in 0 blocks
==12202== Rerun with --leak-check=full to see details of leaked memory
==12202==
==12202== For counts of detected and suppressed errors, rerun with: -v
==12202== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Before using the library you must call its initialization method in order to prepare all the internal constructs necessary to manage the resources.
activemq::library::ActiveMQCPP::initializeLibrary();

Conditional jump or move depends on uninitialised value(s) with SDL2 and C++ class

I'm using Valgrind on Debian 8.2. I ran valgrind -v --tool=memcheck --leak-check=yes --track-origins=yes --log-file=valgrind-$PROGRAM.log ./$PROGRAM where PROGRAM was the name of the program.
Valgrind gave me this complaint several times:
==7125== Conditional jump or move depends on uninitialised value(s)
==7125== at 0xE816EC3: ??? (in /usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.340.96)
==7125== by 0x4E8DB30: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==7125== by 0x4E8DBCF: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==7125== by 0x4E90A92: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==7125== by 0x4E887BF: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==7125== by 0x403ACF: Graphics::Graphics(char const*, int, int, int, unsigned int) (Graphics.cpp:25)
==7125== by 0x401974: Game::run() (Game.cpp:62)
==7125== by 0x403EC5: main (main.cpp:13)
==7125== Uninitialised value was created by a stack allocation
==7125== at 0x4E8D830: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
And this one:
==7125== 28 bytes in 2 blocks are definitely lost in loss record 19 of 125
==7125== at 0x4C28C20: malloc (vg_replace_malloc.c:296)
==7125== by 0x59DCA69: strdup (strdup.c:42)
==7125== by 0x66C66C6: ??? (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==7125== by 0x66C74F4: _XimSetICValueData (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==7125== by 0x66C2A28: _XimLocalCreateIC (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==7125== by 0x66A7E54: XCreateIC (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==7125== by 0x4EEFB30: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==7125== by 0x4EEFF45: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==7125== by 0x4EE30CB: ??? (in /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0)
==7125== by 0x403A88: Graphics::Graphics(char const*, int, int, int, unsigned int) (Graphics.cpp:19)
==7125== by 0x401974: Game::run() (Game.cpp:62)
==7125== by 0x403EC5: main (main.cpp:13)
The lines of main.cpp and Game.cpp Valgrind refers to lead to Graphics.cpp.
Graphics.h looks like this:
#ifndef GRAPHICS_H
#define GRAPHICS_H
struct SDL_Window;
struct SDL_Renderer;
class Graphics {
private:
const char *_windowTitle;
int _windowWidth, _windowHeight;
SDL_Window *_window;
SDL_Renderer *_renderer;
int _renderingDriverIndex;
Uint32 _rendererFlags;
public:
Graphics(const char* windowTitle, int windowWidth, int windowHeight, int renderingDriverIndex, Uint32 renderFlags);
~Graphics();
int windowWidth();
int windowHeight();
void changeWindowSize(int width, int height);
SDL_Renderer* renderer(); // since _renderer is pointer, this func must return a SDL_Renderer pointer
void setBackgroundColor();
void clear();
void update();
};
#endif /* GRAPHICS_H */
The Graphics object constructor looks like this in Graphics.cpp. Valgrind seems to be complaining about the definitions of _window and _renderer:
Graphics::Graphics(const char* windowTitle, int windowWidth, int windowHeight, int renderingDriverIndex, Uint32 renderFlags) :
_windowTitle (windowTitle),
_windowWidth (windowWidth),
_windowHeight (windowHeight),
_renderingDriverIndex (renderingDriverIndex), // get the index of the first graphics driver available(?)
_rendererFlags (renderFlags)
{
_window= SDL_CreateWindow(_windowTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, _windowWidth, _windowHeight, SDL_WINDOW_SHOWN); // LINE 19
if(_window == 0){
printError("SDL_CreateWindow");
SDL_Quit();
}
_renderer= SDL_CreateRenderer(_window, _renderingDriverIndex, _rendererFlags); // LINE 25
if(_renderer == NULL){
printError("SDL_CreateRenderer");
SDL_Quit();
}
if(SDL_SetRenderDrawBlendMode(_renderer, SDL_BLENDMODE_BLEND) == -1){
printError("SDL_SetRenderDrawBlendMode");
SDL_Quit();
}
}
Why does Valgrind complain about uninitialized variables when I define them in either Graphic's member initialization list or the class's object constructor?

string gets cut somewhere

I have class with a method:
Class Strip
with the header:
class Strip : public QMainWindow, public ILog {
And the body:
void Strip::log(const string& msg) {
ui->logFeld->append(QString::fromStdString(msg));
cout << msg << endl;
}
Which is implemented from the interface
struct ILog {
virtual void log(const string&) = 0;
};
Caller Class
In the header file of the calling class the log class is given with:
public:
LoadSetup(ILog *log): log(log) {};
In the body of the function is called with:
log->log("Error file not found or corrupted");
The problem is that cout as well as the QElement only shows: or corrupted.
Where does the rest of the string get lost or more precisely how can I correct it?
Valgrind
valgrind --leak-check=yes ./Strip > LogFile 2>&1 gives a 12k line big outputfile.
Memcheck, a memory error detector
Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
Command: ./Strip
Invalid read of size 4
at 0x6DCD0D3: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DCF464: FcConfigFilename (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DE2A15: FcConfigParseAndLoad (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DD8176: FcInitLoadConfig (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DD8265: FcInitLoadConfigAndFonts (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DD8484: FcInit (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x50773D9: ??? (in /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.1)
by 0x50049C3: QApplicationPrivate::construct(_XDisplay*, unsigned long, unsigned long) (in /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.1)
by 0x5005283: QApplication::QApplication(int&, char**, int) (in /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.1)
by 0x40B275: main (in /home/magu_/Strip/Strip)
Address 0xa0f6814 is 20 bytes inside a block of size 22 alloc'd
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x6DCD02C: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DCF464: FcConfigFilename (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DE2A15: FcConfigParseAndLoad (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DD8176: FcInitLoadConfig (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DD8265: FcInitLoadConfigAndFonts (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DD8484: FcInit (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x50773D9: ??? (in /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.1)
by 0x50049C3: QApplicationPrivate::construct(_XDisplay*, unsigned long, unsigned long) (in /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.1)
by 0x5005283: QApplication::QApplication(int&, char**, int) (in /usr/lib/x86_64-linux-gnu/libQtGui.so.4.8.1)
by 0x40B275: main (in /home/magu_/Strip/Strip)
Invalid read of size 4
at 0x6DCD0E8: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DCF464: FcConfigFilename (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DE2A15: FcConfigParseAndLoad (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DE30FD: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x8FCA6F3: ??? (in /lib/x86_64-linux-gnu/libexpat.so.1.5.2)
by 0x8FCB950: ??? (in /lib/x86_64-linux-gnu/libexpat.so.1.5.2)
by 0x8FC87C6: ??? (in /lib/x86_64-linux-gnu/libexpat.so.1.5.2)
by 0x8FCA17A: ??? (in /lib/x86_64-linux-gnu/libexpat.so.1.5.2)
by 0x8FCD75C: XML_ParseBuffer (in /lib/x86_64-linux-gnu/libexpat.so.1.5.2)
by 0x6DE2B70: FcConfigParseAndLoad (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DD8176: FcInitLoadConfig (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DD8265: FcInitLoadConfigAndFonts (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
Address 0xa0fe9d0 is 16 bytes inside a block of size 18 alloc'd
at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x6DCD02C: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DCF464: FcConfigFilename (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DE2A15: FcConfigParseAndLoad (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DE30FD: ??? (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x8FCA6F3: ??? (in /lib/x86_64-linux-gnu/libexpat.so.1.5.2)
by 0x8FCB950: ??? (in /lib/x86_64-linux-gnu/libexpat.so.1.5.2)
by 0x8FC87C6: ??? (in /lib/x86_64-linux-gnu/libexpat.so.1.5.2)
by 0x8FCA17A: ??? (in /lib/x86_64-linux-gnu/libexpat.so.1.5.2)
by 0x8FCD75C: XML_ParseBuffer (in /lib/x86_64-linux-gnu/libexpat.so.1.5.2)
by 0x6DE2B70: FcConfigParseAndLoad (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
by 0x6DD8176: FcInitLoadConfig (in /usr/lib/x86_64-linux-gnu/libfontconfig.so.1.4.4)
...
LEAK SUMMARY:
definitely lost: 8,775 bytes in 44 blocks
indirectly lost: 18,528 bytes in 555 blocks
possibly lost: 462,846 bytes in 2,014 blocks
still reachable: 1,207,255 bytes in 8,462 blocks
suppressed: 0 bytes in 0 blocks
Reachable blocks (those to which a pointer was found) are not shown.
To see them, rerun with: --leak-check=full --show-reachable=yes
For counts of detected and suppressed errors, rerun with: -v
ERROR SUMMARY: 930 errors from 877 contexts (suppressed: 2 from 2)
Okey most of the errors are false positives comming from Qt, I'll try to suppress those errors and try to fix it.
The problem is can't really understand the output. Any further help would be appritiated