Use correct deallocator for returned buffera.
Don't free internal structure via ASN1_STRING_data.
Deallocate NETSCAPE_SPKI.
PR-URL: https://github.com/nodejs/node/pull/2359
Reviewed-By: Fedor Indutny <fedor@indutny.com>
if (sp == nullptr)
return nullptr;
- const char* buf = nullptr;
- buf = reinterpret_cast<const char*>(ASN1_STRING_data(sp->spkac->challenge));
+ unsigned char* buf = nullptr;
+ ASN1_STRING_to_UTF8(&buf, sp->spkac->challenge);
- return buf;
+ NETSCAPE_SPKI_free(sp);
+
+ return reinterpret_cast<const char*>(buf);
}
Local<Value> outString = Encode(env->isolate(), cert, strlen(cert), BUFFER);
- delete[] cert;
+ OPENSSL_free(const_cast<char*>(cert));
args.GetReturnValue().Set(outString);
}