Oh, I guess you could set `BIO_set_close(bio, BIO_NOCLOSE)` before calling BIO_free(), that stops OpenSSL from freeing the memory that ptr->data points to.  The caller needs to free it with OPENSSL_free() rather than delete[] though.