c++ - Valgrind memory leak with std::string in std::map -
here output valgrind:
==6519== @ 0x4c25885: operator new(unsigned long) (vg_replace_malloc.c:319) ==6519== 0x4ee65d8: std::string::_rep::_s_create(unsigned long, unsigned long, std::allocator<char> const&) (new_allocator.h:104) ==6519== 0x4ee7ce0: char* std::string::_s_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (basic_string.tcc:138) ==6519== 0x4ee80f7: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (basic_string.h:1725) ==6519== 0x41c399: pilinpopts::pilinpopts() (pilinpopts.cpp:12) ==6519== 0x403a55: main (main.cpp:32)
this same error repeated every entry in map.
main.cpp line 32 is:
pilinpopts input;
line 12 of pilinpopts part of constructor:
#include "pilinpopts.h" #include <iostream> #include <fstream> #include <string> #include <sstream> pilinpopts::pilinpopts() { // create map of options, put in alphabetical order ease sorting piloptmap.insert(std::pair<std::string, bool>("bforce",false)); piloptmap.insert(std::pair<std::string, bool>("coef",false)); piloptmap.insert(std::pair<std::string, bool>("dualjet",false)); piloptmap.insert(std::pair<std::string, bool>("flow",false)); piloptmap.insert(std::pair<std::string, bool>("gforce",false)); piloptmap.insert(std::pair<std::string, bool>("gpress",false)); piloptmap.insert(std::pair<std::string, bool>("matlab",false)); piloptmap.insert(std::pair<std::string, bool>("model",false)); piloptmap.insert(std::pair<std::string, bool>("out_shade",false)); piloptmap.insert(std::pair<std::string, bool>("out_shade_file",false)); piloptmap.insert(std::pair<std::string, bool>("press",false)); piloptmap.insert(std::pair<std::string, bool>("proc",false)); piloptmap.insert(std::pair<std::string, bool>("shade",false)); piloptmap.insert(std::pair<std::string, bool>("summary",false)); piloptmap.insert(std::pair<std::string, bool>("trans",false)); // need define default filepaths, needed because optional platpath = ""; vehpath = ""; apppath = ""; dockpath = ""; };
i found posts in said valgrind may produce false positives. example: std::string memory leak
is false positive since std::string has constructors etc needs this? or should change use c character arrays in map?
one of probable reasons of behavior may memory pooling in c++ standard library implementation.
from valgrind faq:
memory quite number of destructed objects not freed , given os, kept in pool(s) later re-use. fact pools not freed @ exit of program cause valgrind report memory still reachable. behaviour not free pools @ exit called bug of library though.
you can set glibcxx_force_new
environment variable before running app force stl free memory possible.
see these links on details of libstdc++ memory allocator implementation:
Comments
Post a Comment