Thank you for you comments, problem resolved. I divided this line into two lines
char* retval = (char*)ToCString(String::Utf8Value(result)); =============> String::Utf8Value retv(result); char* retval = (char*)ToCString(retv); Just create an explicit object of String::Utf8Value, then I can use it and it will not be destroyed automatically before the function returns. On Fri, Jun 12, 2015 at 3:21 PM, Sven Panne <[email protected]> wrote: > On Fri, Jun 12, 2015 at 5:47 AM, solar <[email protected]> wrote: >> >> [...] >> char* retval = (char*)ToCString(String::Utf8Value(result)); >> printf("retval = %s, %p \n", retval, retval); >> >> > That's a classical use-after-free bug: String::Utf8Value(result) results > in a temporary object which is dead after the first line, see > http://en.cppreference.com/w/cpp/language/lifetime#Temporary_object_lifetime. > String::Utf8Value's destructor frees the underlying buffer, so retval > always points to dead memory. Depending on your compiler/runtime/etc. > anything can happen when you use that. Hint: Use e.g. valgrind/ASAN/... or > other memory debuggers to easily find such bugs. > > -- > -- > v8-users mailing list > [email protected] > http://groups.google.com/group/v8-users > --- > You received this message because you are subscribed to a topic in the > Google Groups "v8-users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/v8-users/kwTLzUerG4o/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
