0

I trying to understand why I'm getting error when I insert some value in std::unordered_map of c++, my binder is like bellow:

#include <node.h>
#include <iostream>
#include <unordered_map>

namespace demo {
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::String;
using v8::Value;
using v8::Number;
using v8::Array;
using v8::Exception;

void Process(const FunctionCallbackInfo<Value>& args) {
    Isolate* isolate = args.GetIsolate();

    std::unordered_map<int,int> t;
    std::cout << "Trying to insert in hash..." << std::endl;
    t.insert(std::pair<int,int>(1,10));
    std::cout << "Doesn't come here..." << std::endl;

    args.GetReturnValue();
}


void init(Local<Object> exports) {
    NODE_SET_METHOD(exports, "process", Process);
}

NODE_MODULE(addon, init)

}

I got error in insert method of std::unordered_map. The error bellow:

*** Error in `node': munmap_chunk(): invalid pointer: 0x00007ffd15e328b0     ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x77725)[0x7fbfae4e5725]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x1a8)[0x7fbfae4f1c18]     node(_ZNSt10_HashtableIiSt4pairIKiiESaIS2_ENSt8__detail10_Select1stESt8equal_toIiESt4hashIiENS4_18_Mod_range_hashingENS4_20_Default_ranged_hashENS4_20_Prime_rehash_policyENS4_17_Hashtable_traitsILb0ELb0ELb1EEEE21_M_insert_unique_nodeEmmPNS4_10_Hash_nodeIS2_Lb0EEE+0x129)[0x116d2a9]

Someone to help?

  • What compiler are you using ? Does it crash with a simple program as well i.e. w/o the node inclusions ? You are certainly not showing all the code. The map in that function is pretty much useless. – Arunmu Sep 01 '16 at 21:06
  • Oh sorry, I agree with you, I'm using g++ (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2)) I've tried as a simples program and it works, only crash when I try to use in node native addon with node-gyp, like I post: ** t.insert(std::pair(1,10));** It works for method size() in this context, but the method insert I get that error as before. – Anderson Pimentel Sep 02 '16 at 01:10
  • Is there a solution? I get the same error using unordered structures in node-gyp – Ruan Kotovich May 12 '18 at 03:19

0 Answers0