Openssl crashes plugin: malloc(): invalid size (unsorted)

I’m trying to decrypt a message using a public key but keep getting: malloc(): invalid size (unsorted)

Here’s what I did:

1- Added this to CMakeLists.txt:

target_link_libraries(Myproject PRIVATE
ssl crypto
)

2- Included openssl’s header files

#include <openssl/rsa.h>
#include <openssl/sha.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <openssl/bio.h>
#include <openssl/evp.h>

3- Tried implementing:

BIO* bio = BIO_new(BIO_s_mem());
BIO_puts(bio, public_key_str.c_str());

and

BIO* bio = BIO_new_mem_buf(public_key_str.c_str(), public_key_str.length());

but both fail with the same message when I try to run the plugin:

malloc(): invalid size (unsorted)

4- Implemented the same functions on a separate cpp project (without JUCE and without CMake) and it works as it should.

Any ideas?
I appreciate the help.