Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. ==1419== Invalid free() / delete / delete[] / realloc()
  2. ==1419== at 0x4A06F1C: operator delete[](void*) (vg_replace_malloc.c:515)
  3. ==1419== by 0x4C3928F: openstreetmap::cOsmBlob::~cOsmBlob() (cOsmBlob.cc:129)
  4. ==1419== by 0x4045DF: void __gnu_cxx::new_allocator<openstreetmap::cOsmBlob>::destroy<openstreetmap::cOsmBlob>(openstreetmap::cOsmBlob*) (new_allocator.h:114)
  5. ==1419== by 0x404005: std::deque<openstreetmap::cOsmBlob, std::allocator<openstreetmap::cOsmBlob> >::pop_front() (stl_deque.h:1407)
  6. ==1419== by 0x403D39: std::queue<openstreetmap::cOsmBlob, std::deque<openstreetmap::cOsmBlob, std::allocator<openstreetmap::cOsmBlob> > >::pop() (stl_queue.h:240)
  7. ==1419== by 0x403BD6: threading::cFifoBuffer<openstreetmap::cOsmBlob>::~cFifoBuffer() (storage.h:86)
  8. ==1419== by 0x403A15: main (main.cc:40)
  9. ==1419== Address 0x50be390 is 752 bytes inside a block of size 7,152 free'd
  10. ==1419== at 0x4A077E6: free (vg_replace_malloc.c:446)
  11. ==1419== by 0x37A6209B3A: inflateEnd (inflate.c:1261)
  12. ==1419== by 0x4C39156: openstreetmap::cOsmBlob::cOsmBlob(std::basic_ifstream<char, std::char_traits<char> >*) (cOsmBlob.cc:116)
  13. ==1419== by 0x4C5B157: openstreetmap::cPbfPipelineFileReader::run(void*) (cPbfPipelineFileReader.cc:158)
  14. ==1419== by 0x37A5A07D14: start_thread (pthread_create.c:308)
  15. ==1419== by 0x37A4EF246C: clone (clone.S:114)
  16. ==1419==
  17. ==1419== Invalid free() / delete / delete[] / realloc()
  18. ==1419== at 0x4A06F1C: operator delete[](void*) (vg_replace_malloc.c:515)
  19. ==1419== by 0x4C3928F: openstreetmap::cOsmBlob::~cOsmBlob() (cOsmBlob.cc:129)
  20. ==1419== by 0x4045DF: void __gnu_cxx::new_allocator<openstreetmap::cOsmBlob>::destroy<openstreetmap::cOsmBlob>(openstreetmap::cOsmBlob*) (new_allocator.h:114)
  21. ==1419== by 0x404604: std::deque<openstreetmap::cOsmBlob, std::allocator<openstreetmap::cOsmBlob> >::_M_pop_front_aux() (deque.tcc:520)
  22. ==1419== by 0x404027: std::deque<openstreetmap::cOsmBlob, std::allocator<openstreetmap::cOsmBlob> >::pop_front() (stl_deque.h:1411)
  23. ==1419== by 0x403D39: std::queue<openstreetmap::cOsmBlob, std::deque<openstreetmap::cOsmBlob, std::allocator<openstreetmap::cOsmBlob> > >::pop() (stl_queue.h:240)
  24. ==1419== by 0x403BD6: threading::cFifoBuffer<openstreetmap::cOsmBlob>::~cFifoBuffer() (storage.h:86)
  25. ==1419== by 0x403A15: main (main.cc:40)
  26. ==1419== Address 0x5eb45d0 is not stack'd, malloc'd or (recently) free'd
  27.  
  28. #define MAX_BLOB_HEADERSIZE (64 * 1024)
  29. #define MAX_BLOB_DATASIZE (32 * 1024 * 1024)
  30.  
  31. cOsmBlob::cOsmBlob(std::ifstream *stream) {
  32. char headerLength[4], *buffer;
  33. pbf::BlobHeader header;
  34. uint32_t length;
  35. pbf::Blob blob;
  36. int retval;
  37.  
  38. if (stream == NULL)
  39. throw std::exception();
  40.  
  41. stream->read(headerLength, 4);
  42. length = ntohl(*((uint32_t*)&headerLength));
  43. if (length == 0 || length > MAX_BLOB_HEADERSIZE) {
  44. cerr << "cOsmBlob: invalid blob header size" << endl;
  45. throw exception();
  46. }
  47.  
  48. /* read the BlobHeader */
  49. buffer = new char[length];
  50. stream->read(buffer, length);
  51. if (header.ParseFromArray(buffer, length) == false) {
  52. cerr << "cOsmBlob: unable to read BlobHeader" << endl;
  53. delete[] buffer;
  54. throw exception();
  55. }
  56. delete[] buffer;
  57.  
  58. /* read the Blob */
  59. if (header.datasize() == 0 || header.datasize() > MAX_BLOB_DATASIZE) {
  60. cerr << "cOsmBlob: invalid header->datasize()" << endl;
  61. throw exception();
  62. }
  63. buffer = new char[header.datasize()];
  64. stream->read(buffer, header.datasize());
  65. if (blob.ParseFromArray(buffer, header.datasize()) == false) {
  66. cerr << "cOsmBlob: unable to read Blob" << endl;
  67. delete[] buffer;
  68. throw exception();
  69. }
  70. delete[] buffer;
  71.  
  72. if (header.type() == "OSMHeader") {
  73. this->type = OSM_HEADER;
  74. }
  75. else if (header.type() == "OSMData") {
  76. this->type = OSM_DATA;
  77. }
  78. else {
  79. cerr << "cOsmBlob: Unknown BlobHeader type" << endl;
  80. throw exception();
  81. }
  82.  
  83. /* extract data */
  84. this->size = 0;
  85. this->rawdata = NULL;
  86. if (blob.has_raw() == true) {
  87. this->rawdata = new char[blob.raw().length()];
  88. memcpy(this->rawdata, blob.raw().data(), blob.raw().length());
  89. this->size = blob.raw().length();
  90. }
  91. else if (blob.has_zlib_data() == true) {
  92. z_stream zlibStream;
  93.  
  94. this->rawdata = new char[blob.raw_size()];
  95. zlibStream.next_in =
  96. (Bytef*)const_cast<char*>(blob.zlib_data().data());
  97. zlibStream.avail_in = blob.zlib_data().size();
  98. zlibStream.next_out = (Bytef*)this->rawdata;
  99. zlibStream.avail_out = blob.raw_size();
  100. zlibStream.zalloc = Z_NULL;
  101. zlibStream.zfree = Z_NULL;
  102. zlibStream.opaque = Z_NULL;
  103.  
  104. if (inflateInit(&zlibStream) != Z_OK) {
  105. cerr << "cOsmBlob: " <<
  106. "Unknown or unsupported ZLib version of blob's data" <<
  107. endl;
  108. delete[] buffer;
  109. throw exception();
  110. }
  111. retval = inflate(&zlibStream, Z_FINISH);
  112. if (retval != Z_OK && retval != Z_STREAM_END) {
  113. cerr << "cOsmBlob: Unable to decompress blob's data" << endl;
  114. delete[] buffer;
  115. throw exception();
  116. }
  117. if (inflateEnd(&zlibStream) != Z_OK) {
  118. cerr << "cOsmBlob: " <<
  119. "Unable to finalize decompression of blob's data" << endl;
  120. delete[] buffer;
  121. throw exception();
  122. }
  123.  
  124. this->size = blob.raw_size();
  125. }
  126. }
  127.  
  128. cOsmBlob::~cOsmBlob(void) {
  129. if (this->rawdata != NULL)
  130. delete[] this->rawdata;
  131. this->rawdata = NULL;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement