Hy, I am trying to encode an X509 certificate into base64, and since the encoder I'm using takes only char*, and typecasting doesn't work, i find a different way to do this. I'm sure there is a simpler way, but i just can't find it. Here is the code:
BUF_MEM *bptr;
BIO* mem = BIO_new(BIO_s_mem());
PEM_write_bio_X509(mem, x509p);
int i = BIO_get_mem_data(mem, &bptr);
_TCHAR* tmp = new _TCHAR( i+1 );
memcpy(tmp, bptr, i);
tmp[ i ] = _T('\0');
BIO_free_all(mem);
X509_free(x509p);
The whole thing works "fine", but after this part every "new" object i create fails, and throws an std::bad_alloc exception. (I delete the tmp later on.
Here is the more exact part where it crashes:
void *__CRTDECL operator new(size_t size) _THROW1(_STD bad_alloc)
{ // try to allocate size bytes
void *p;
while ((p = malloc(size)) == 0)
if (_callnewh(size) == 0)
{ // report no memory
static const std::bad_alloc nomem;
_RAISE(nomem);
}
return (p);
}
I know it has something to do with memory leaks, but i can't find anything wrong with it, or I'm just missing it. The problem was caused only by this part of the code, if I remove it, everything is fine again.
Thank you for the help. (and Merry Christmas)