dst_lib_init() crashes

Hi All,

I called this function twice in my test program and it crashes in second call inside dst_lib_init()
Can you please help in finding the issue here. Seems like some sort of memory issue


void calltoentropy()
{
        CCryptoTools::InitializeOpenSSL();
        isc_mem_t *mctx = NULL;
        dst_key_t *keyp = NULL;
        isc_result_t retStatus;


        // setup required stuffs
        retStatus=isc_mem_create(static_cast<size_t>(0), static_cast<size_t>(0), &mctx);
        isc_entropy_t *ectx = NULL;


        cout<<"Before isc_entropy_create ectx is "<<ectx<<"and address of ectx is "<<&ectx<<"return status is "<<retStatus<<endl;
        retStatus=isc_entropy_create(mctx, &ectx);
        cout<<"after isc_entropy_create return status is"<<retStatus<< " mctx::"<<mctx<< "and ectx"<<ectx<<" and ectx address"<<&ectx<<endl;


        retStatus=dst_lib_init(mctx,ectx, static_cast<size_t>(0));
        cout<<"dst_lib_init"<<retStatus<<endl;


        isc_entropy_detach(&ectx);
        cout<<"isc_entropy_detach "<<ectx<<"-"<<&ectx<<endl;


        dst_lib_destroy();
        cout<<"dst_lib_destroy()"<<endl;


        if ( ISC_R_SUCCESS == retStatus )
        {
                cout<<" ISC_R_SUCESS is return status"<<retStatus<<endl;
        }
        else
        {
                cout<<"just return"<<endl;
        }

Output
starting call entropy
**********************
Before isc_entropy_create ectx is 0and address of ectx is 0x7fff848126a0return status is 0
after isc_entropy_create return status is0 mctx::0xd8ab10and ectx0x7fd61813b010 and ectx address0x7fff848126a0
dst_lib_init0
isc_entropy_detach 0-0x7fff848126a0
dst_lib_destroy()
ISC_R_SUCESS is return status0
starting call entropy**************************
Before isc_entropy_create ectx is 0and address of ectx is 0x7fff848126a0return status is 0
after isc_entropy_create return status is0 mctx::0xd8ac80and ectx0x7fd6180fa010 and ectx address0x7fff848126a0
Segmentation fault (core dumped)

Backtrace
Program received signal SIGSEGV, Segmentation fault.
__GI___pthread_rwlock_wrlock (rwlock=0x0) at pthread_rwlock_wrlock.c:27
27 int result = __pthread_rwlock_wrlock_full (rwlock, NULL);
(gdb) bt
#0 __GI___pthread_rwlock_wrlock (rwlock=0x0) at pthread_rwlock_wrlock.c:27
#1 0x00007ffff6b5be7d in CRYPTO_THREAD_write_lock (lock=<optimized out>) at crypto/threads_pthread.c:78
#2 0x00007ffff6b1e92b in RAND_get_rand_method () at crypto/rand/rand_lib.c:853
#3 RAND_get_rand_method () at crypto/rand/rand_lib.c:846
#4 0x00007ffff6b1ed7d in RAND_status () at crypto/rand/rand_lib.c:962
#5 0x00007ffff7074f7f in dst__openssl_init (engine=<optimized out>, engine@entry=0x0) at …/…/…/lib/dns/openssl_link.c:296
#6 0x00007ffff707c4d7 in dst_lib_init2 (mctx=<optimized out>, eflags=0, engine=0x0, ectx=0x7ffff5778010) at …/…/…/lib/dns/dst_api.c:198
#7 dst_lib_init2 (mctx=<optimized out>, ectx=0x7ffff5778010, engine=0x0, eflags=0) at …/…/…/lib/dns/dst_api.c:154
#8 0x000000000043e1ba in calltoentropy () at testcertificate.cpp:1732
#9 0x000000000043e3b9 in VerifyCertificateFormatSuite (strTestCase=0x5d5860 "VerifyCerficate Format[22] ", ssdkSecurityManagerInterface=…, userToken=0x5c4df0)
at testcertificate.cpp:1799
#10 0x000000000047ffc9 in TestCase::Execute (this=0x4faeb0 <testCases+1008>, id=22, ssdkSecurityManagerInterface=…, userToken=0x5c4df0) at testcommon.h:585
#11 0x000000000047676b in NonInteractiveTest (reqTestCase=22, ssdkSecurityManagerInterface=…, userToken=0x5c4df0, argc=2, argv=0x7fffffffd978)
at testcertificate.cpp:5158
#12 0x0000000000476e1b in main (argc=2, argv=0x7fffffffd978) at testcertificate.cpp:5246

Looking forward for help to resolve this issue

Thank You