c++ - Strange error while using valgrind? a bug maybe? -


i developing c++ program , when finished, wanted check memory leaks, have found strange error valgrind:

   ==9106== invalid free() / delete / delete[] / realloc()    ==9106==    @ 0x4006c58: free (vg_replace_malloc.c:427)    ==9106==    0x42eb637d: free_mem (in /lib/libc-2.5.so)    ==9106==    0x42eb5f16: __libc_freeres (in /lib/libc-2.5.so)    ==9106==    0x4002451: _vgnu_freeres (vg_preloaded.c:61)    ==9106==    0x42e38ea3: _exit (in /lib/libc-2.5.so)    ==9106==    0x42dc0df3: (below main) (in /lib/libc-2.5.so)    ==9106==  address 0x403f818 not stack'd, malloc'd or (recently) free'd 

since did not tell line number invalid delete present, had use method of commenting blocks out.

the surprise got until point commented code, , error still appearing.

i have code:

int main(int argc, char** argv) {     /* ... other code */     return 0; } 

what happening here? vagrind bug? so, can safely ignore error?

i running valgrind 3.7.0 way (under linux):

$ valgrind --track-origins=yes --leak-check=full --show-reachable=yes ./bioweds_client 

edit:

this whole code:

/*   * file:   main.cpp  * author: jstuardo  *  * created on march 22, 2013, 7:32 pm  */   #include <cstdlib> #include <iostream> /* #include <string> #include <map>  #include "settings.h" #include "fcomm.h" #include "log.h" #include "helper.h"  using namespace std;  static string get_optional_parameter(std::map<string, string> parameters, string key) {     if (parameters.count(key) == 0)         return "";     else         return parameters[key]; }  static bool show_usage(std::string name) {     std::cerr << "uso: " << name << " opciones\n\n"             << "las opciones posibles son:\n"             << "\t--command comando\tcomando que se les envía los equipos biométricos\n"             << "\t--ip ip\t\t\tespecifica la dirección ip de un equipo\n"             << "\t--staff staff\t\tespecifica el id de un funcionario\n"             << "\t--date_from fecha\tespecifica la fecha de inicio de una consulta la base de datos\n"             << "\t--date_to fecha\t\tespecifica la fecha de término de una consulta la base de datos\n"             << "\t--fingers dedos\t\tespecifica los dedos de ambas manos para las cuales realizar una oepración\n"             << "\t--verbose\t\tmuestra por consola la operación de la aplicación\n"             << "\t--retries intentos\t\tcantidad de intentos que debe realizar para la conexión en caso de error de comunicación\n"             << "\t--delay retardo\t\tcantidad de milisegundos esperar luego que se envía el comando\n"             << "\t--thread\t\tenvía los comandos los equipos mediante threads\n"             << "\t--source source \t\tespecifica archivo existente en el equipo indicado por ip\n"             << "\t--target target \t\tespecifica archivo crear en el pc\n\n"             << "los comandos posibles son:\n"             << "\tcheck\tverifica la comunicación con el equipo dado por el parámetro --ip\n"             << "\tbroadcast\ttransmite todos los archivos existentes en la carpeta \"" << fcomm::share_folder << "\" todos los equipos configurados, excepto al indicado por el parámeto --ip\n"             << "\tset_time\tsincroniza la fecha y hora de todos los equipos configurados con la fecha y hora del pc\n"             << "\tget_fingerprints\tobtiene los archivos de huellas desde el equipo indicado por el parámetro --ip del funcionario indicado por el parámetro --staff\n"             << "\tdelete_fingerprints\tborra las huellas de todos los equipos configurados. las huellas se indican con el parámetro --fingers como sigue:    0:1:2:3:4:5:6:7:8:9 (para todos o algunos de los dedos\n"             << "\tget_logs\tobtiene las marcaciones existentes en los equipos configurados (archivos wdjl y los almacena en la carpeta \"" << fcomm::wdjl_folder << "\")\n"             << "\tprocess_logs\tprocesa todos los registros existentes en la carpeta \"" << fcomm::wdjl_folder << "\"\n"             << "\tget_archives\tobtiene el archivo de funcionarios y los almacena en la carpeta \"" << fcomm::share_folder << "\")\n"             << "\tget_photos\tobtiene las fotos de las marcas que aún no tienen foto de todos los equipos configurados. si se especifican fechas, se traen solo las fotos de las marcas de ese intervalo.\n"             << "\tget_one_photo\tobtiene una única foto desde el equipo indicado por ip." << endl;      return true; } */  /*  *   */ int main(int argc, char** argv) {     std::cout << "all commented" << std::endl;     return 0;     /*     bool verbose = false;     bool multithread = false;     int retries = 0;     int delay = 0;     std::string command;     std::map<string, string> parameters;      // lee los parámetros de la línea de comandos     (int = 1; < argc; ++i) {         if (string(argv[i]) == "--command") {             if (i + 1 < argc)                 command = argv[++i];         } else if (string(argv[i]) == "--ip") {             if (i + 1 < argc)                 parameters["ip"] = argv[++i];         } else if (string(argv[i]) == "--staff") {             if (i + 1 < argc)                 parameters["staff"] = argv[++i];         } else if (string(argv[i]) == "--date_from") {             if (i + 1 < argc)                 parameters["date_from"] = argv[++i];         } else if (string(argv[i]) == "--date_to") {             if (i + 1 < argc)                 parameters["date_to"] = argv[++i];         } else if (string(argv[i]) == "--fingers") {             if (i + 1 < argc)                 parameters["fingers"] = argv[++i];         } else if (string(argv[i]) == "--retries") {             if (i + 1 < argc)                 retries = atoi(argv[++i]);         } else if (string(argv[i]) == "--delay") {             if (i + 1 < argc)                 delay = atoi(argv[++i]);         } else if (string(argv[i]) == "--verbose") {             verbose = true;         } else if (string(argv[i]) == "--thread") {             multithread = true;         } else if (string(argv[i]) == "--source") {             if (i + 1 < argc)                 parameters["source"] = argv[++i];         } else if (string(argv[i]) == "--target") {             if (i + 1 < argc)                 parameters["target"] = argv[++i];         }     }      string executable = argv[0];     executable = executable.substr(executable.find_last_of("/") + 1);      bool salida = false;      if (command == "")         salida |= show_usage(executable);     else if (command == "get_fingerprints" && (parameters.count("ip") == 0 || parameters.count("staff") == 0))         salida |= show_usage(executable);     else if (command == "delete_fingerprints" && parameters.count("fingers") == 0)         salida |= show_usage(executable);     else if (command == "get_bulk_photos" && parameters.count("ip") == 0)         salida |= show_usage(executable);     else if (command == "delete_bulk_photos" && parameters.count("ip") == 0)         salida |= show_usage(executable);     else if (command == "get_archives" && parameters.count("ip") == 0)         salida |= show_usage(executable);         else if (command == "get_one_photo" && parameters.count("ip") == 0 && parameters.count("source") == 0 && parameters.count("target") == 0)         salida |= show_usage(executable);      if (command != "check" && command != "broadcast" && command != "set_time" && command != "get_fingerprints"             && command != "delete_fingerprints" && command != "get_logs" && command != "process_logs"             && command != "get_photos" && command != "get_bulk_photos" && command != "delete_bulk_photos"              && command != "get_one_photo" && command != "get_archives" && command != "decrypt_file")         salida |= show_usage(executable);      if (salida)         return exit_failure;      helper::checkfolder(fcomm::log_folder);     log log(fcomm::log_folder + "common.log");      if (verbose) {         cout << "ejecutando comando [" << command << "] con los parámetros:" << endl;         (map<string, string>::iterator = parameters.begin(); != parameters.end(); it++)             cout << "\t" << it->first << " = " << it->second << endl;          cout << "\treintentos = " << retries << endl;          cout << "\tretardo = " << delay << " milisegundos" << endl;          if (multithread) cout << "\tmultithread" << endl;         else cout << "\tsecuencial" << endl;     }      log.write("ejecutando comando [" + command + "] con los parámetros:");     (map<string, string>::iterator = parameters.begin(); != parameters.end(); it++)         log.write("\t" + it->first + " = " + it->second);      if (multithread) log.write("\tmultithread");     else log.write("\tsecuencial");      settings settings;     fcomm fcomm(settings, retries, delay, verbose, multithread);      bool exito = false;     if (command == "check")         exito = fcomm.check(get_optional_parameter(parameters, "ip"));     else if (command == "broadcast")         exito = fcomm.broadcast(get_optional_parameter(parameters, "ip"));     else if (command == "set_time")         exito = fcomm.settime(get_optional_parameter(parameters, "ip"));     else if (command == "get_fingerprints")         exito = fcomm.getfingerprints(parameters["staff"], parameters["ip"]);     else if (command == "delete_fingerprints")         exito = fcomm.deletefingerprints(parameters["staff"], get_optional_parameter(parameters, "ip"), get_optional_parameter(parameters, "fingers"));     else if (command == "get_logs")         exito = fcomm.getlogs(get_optional_parameter(parameters, "ip"));     else if (command == "process_logs")         exito = fcomm.processlogs();     else if (command == "get_archives")         exito = fcomm.getarchives(get_optional_parameter(parameters, "ip"));         else if (command == "get_photos")         exito = fcomm.getphotos(get_optional_parameter(parameters, "ip"), get_optional_parameter(parameters, "date_from"), get_optional_parameter(parameters, "date_to"));     else if (command == "get_one_photo")         exito = fcomm.getonephoto(parameters["ip"], parameters["source"], parameters["target"]);     else if (command == "decrypt_file")         exito = fcomm.decryptfile(parameters["source"]);      log.write("saliendo en forma exitosa.");      return exito ? exit_success : exit_failure;      */ } 

and whole valgrind output:

[root@linux v2]# valgrind --track-origins=yes --leak-check=full --show-reachable=yes ./bioweds_client ==10441== memcheck, memory error detector ==10441== copyright (c) 2002-2011, , gnu gpl'd, julian seward et al. ==10441== using valgrind-3.7.0 , libvex; rerun -h copyright info ==10441== command: ./bioweds_client ==10441==  commented ==10441== invalid free() / delete / delete[] / realloc() ==10441==    @ 0x4006c58: free (vg_replace_malloc.c:427) ==10441==    0x42eb637d: free_mem (in /lib/libc-2.5.so) ==10441==    0x42eb5f16: __libc_freeres (in /lib/libc-2.5.so) ==10441==    0x4002451: _vgnu_freeres (vg_preloaded.c:61) ==10441==    0x42e38ea3: _exit (in /lib/libc-2.5.so) ==10441==    0x42dc0df3: (below main) (in /lib/libc-2.5.so) ==10441==  address 0x403f818 not stack'd, malloc'd or (recently) free'd ==10441==  ==10441==  ==10441== heap summary: ==10441==     in use @ exit: 0 bytes in 0 blocks ==10441==   total heap usage: 8 allocs, 9 frees, 186 bytes allocated ==10441==  ==10441== heap blocks freed -- no leaks possible ==10441==  ==10441== counts of detected , suppressed errors, rerun with: -v ==10441== error summary: 1 errors 1 contexts (suppressed: 33 8) [root@linux v2]#  

thanks in advance,

jaime

this bug in libc has been fixed.
can ignore bug, or use valgrind option --run-libc-freeres=no avoid it.

__libc_freeres called @ exit release resources; bug memory allocated separate pool being returned libc malloc/free area.

for details, see http://valgrind.org/docs/manual/faq.html#faq.exit_errors , https://bugzilla.redhat.com/show_bug.cgi?id=629976


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -