日期:2014-05-16  浏览次数:20951 次

关于OPENSSL的一个问题
在测试的时候,怎么测试都没有问题,结果上了生产后,就报了:
*** glibc detected *** ./SSRPQT: free(): invalid next size (fast): 0x0a119d70 ***
======= Backtrace: =========
/lib/libc.so.6[0x2bb595]
/lib/libc.so.6(cfree+0x59)[0x2bb9d9]
/lib/libcrypto.so.6(CRYPTO_free+0x3a)[0x448da5a]
/lib/libcrypto.so.6(BUF_MEM_free+0x47)[0x4412f07]
/lib/libcrypto.so.6[0x4414783]
/lib/libcrypto.so.6(BIO_free+0xc1)[0x4413f01]
/lib/libcrypto.so.6(BIO_free_all+0x34)[0x4413f54]
错误!SSRPQT是我的应用程序,我是把ssl的加解密放入了libcrypto.so中,然后供SSRPQT调用的。

有谁懂OpenSSL的,帮忙看下啊,
代码如下:

std::string Decrypt( const std::string& sInbuf, const std::string& sKey)
{
const char* inbuf = sInbuf.c_str();
unsigned char * key = (unsigned char *)sKey.c_str();
int inlen = sInbuf.length();
BIO *bio, *mbio, *cbio;
    char *dst;
    int outlen;
    
    mbio = BIO_new( BIO_s_mem( ) );
    cbio = BIO_new( BIO_f_cipher( ) );
    BIO_set_cipher( cbio , EVP_des_ecb( ) , key , NULL , 0 );
    
    bio = BIO_push( cbio , mbio );
    BIO_write( bio , inbuf , inlen );
    BIO_flush( bio );
    
outlen = BIO_get_mem_data( mbio , (char **) & dst );
dst[outlen] = '\0';
string sResult = dst;
BIO_free_all( bio );

    return sResult;
}

------解决方案--------------------
BIO_free_all( bio )这里面会对bio多次free吗?