fix memory leak and read after free
fix memory leak and read after free

Example code:
int main()
{
	...
	r = C_Initialize(NULL);
	assert(r == CKR_OK);
	r = C_GetSlotList(CK_TRUE, NULL_PTR, &slot_cnt);
	assert(r == CKR_OK);
	assert(slot_cnt >= 1);
	r = C_GetSlotList(TRUE, &slot, &slot_cnt);
	assert(r == CKR_OK);
	r = C_OpenSession(slot, CKF_SERIAL_SESSION | CKF_RW_SESSION, 0, 0, &hndl_session);
	assert(r == CKR_OK);
	assert(hndl_session != CK_INVALID_HANDLE);
	r = C_Login(hndl_session, CKU_USER, pin, sizeof(pin));
	assert(r == CKR_OK);
	r = C_CreateObject(hndl_session, data_tmpl,
			sizeof(data_tmpl)/sizeof(data_tmpl[0]), &hndl);
	assert(r == CKR_OK);
	r = C_DestroyObject(hndl_session, hndl);
	assert(r == CKR_OK);

	r = C_GenerateKeyPair(hndl_session, &rsa_genkp_mech, rsa_pbkey_tmpl,
			sizeof(rsa_pbkey_tmpl)/sizeof(rsa_pbkey_tmpl[0]), rsa_prkey_tmpl,
			sizeof(rsa_prkey_tmpl)/sizeof(rsa_prkey_tmpl[0]),
			&hndl_pb, &hndl_pr);
	assert(r == CKR_OK);

	r = C_Finalize(NULL);
	assert(r == CKR_OK);
	return 0;
}

==20626== Invalid read of size 4
==20626==    at 0x41036B: pkcs15_add_object (framework-pkcs15.c:679)
==20626==    by 0x410B27: pkcs15_gen_keypair (framework-pkcs15.c:1761)
==20626==    by 0x40980D: C_GenerateKeyPair (pkcs11-object.c:869)
==20626==    by 0x4078CD: main (pkcs11_1.c:71)
==20626==  Address 0x632d3e0 is 0 bytes inside a block of size 584 free'd
==20626==    at 0x4C24A28: free (vg_replace_malloc.c:325)
==20626==    by 0x4E5452B: sc_pkcs15init_delete_object (pkcs15-lib.c:2903)
==20626==    by 0x41243B: pkcs15_dobj_destroy (framework-pkcs15.c:2721)
==20626==    by 0x40AD91: C_DestroyObject (pkcs11-object.c:96)
==20626==    by 0x407871: main (pkcs11_1.c:68)
==20626== 
==20626== 80 bytes in 1 blocks are definitely lost in loss record 76 of 148
==20626==    at 0x4C24137: calloc (vg_replace_malloc.c:418)
==20626==    by 0x40E383: __pkcs15_create_object (framework-pkcs15.c:250)
==20626==    by 0x40E45C: __pkcs15_create_data_object (framework-pkcs15.c:439)
==20626==    by 0x41164C: pkcs15_create_data (framework-pkcs15.c:1441)
==20626==    by 0x411760: pkcs15_create_object (framework-pkcs15.c:1490)
==20626==    by 0x409A35: C_CreateObject (pkcs11-object.c:53)
==20626==    by 0x40783A: main (pkcs11_1.c:65)
==20626== 
==20626== LEAK SUMMARY:
==20626==    definitely lost: 80 bytes in 1 blocks



git-svn-id: 444ed946b9c2220da791e84c3dd156a05f92db99@3799 c6295689-39f2-0310-b995-f0e70906c6a9

ieugen/OpenSC,gentoo/OpenSC,kasparsd/opensc-latvia-id,dengert/OpenSC,gemini/OpenSC,velter/OpenSC,dirkx/OpenSC.tokend,hhonkanen/OpenSC,tidatida/OpenSC,CardContact/OpenSC,LudovicRousseau/OpenSC,mtrojnar/OpenSC,carlhoerberg/OpenSC,gentoo/OpenSC,hongquan/OpenSC-main,philipWendland/OpenSC,gemini/OpenSC,adminmt/OpenSC,germanblanco/OpenSC,dirkx/OpenSC,dengert/OpenSC,fabled/OpenSC,frankmorgner/OpenSC,AktivCo/OpenSC,0x7678/OpenSC,viktorTarasov/OpenSC-SM,0x7678/myOpenSC,l1k/OpenSC,velter/OpenSC,martinpaljak/OpenSC,metsma/OpenSC,fabled/OpenSC,mouse07410/OpenSC,metsma/OpenSC,OpenSC/OpenSC,0x7678/OpenSC,ieugen/OpenSC,viktorTarasov/OpenSC-SM,aobaid/OpenSC,martinpaljak/OpenSC,Jakuje/OpenSC,kasparsd/opensc-latvia-id,fabled/OpenSC,tidatida/OpenSC,kasparsd/opensc-latvia-id,hongquan/OpenSC-main,0x7678/myOpenSC,nmav/OpenSC,nmav/OpenSC,gentoo/OpenSC,mtrojnar/OpenSC,dirkx/OpenSC.tokend,dirkx/OpenSC.tokend,UIKit0/OpenSC,OpenSC/OpenSC,dirkx/OpenSC.tokend,UIKit0/OpenSC,carlhoerberg/OpenSC,Jakuje/OpenSC,AktivCo/OpenSC,l1k/OpenSC,Jakuje/OpenSC,0x7678/OpenSC,ieugen/OpenSC,carlhoerberg/OpenSC,CardContact/OpenSC,rickyepoderi/OpenSC,Jakuje/OpenSC,tidatida/OpenSC,fabled/OpenSC,rickyepoderi/OpenSC,adminmt/OpenSC,marschap/pkg-opensc,mtrojnar/OpenSC,financeX/OpenSC,viktorTarasov/OpenSC-SM,marschap/pkg-opensc,frankmorgner/OpenSC,ieugen/OpenSC,philipWendland/OpenSC,dirkx/OpenSC,germanblanco/OpenSC,velter/OpenSC,0x7678/myOpenSC,jpki/OpenSC,financeX/OpenSC,financeX/OpenSC,dirkx/OpenSC,adminmt/OpenSC,0x7678/myOpenSC,gemini/OpenSC,hongquan/OpenSC-main,aobaid/OpenSC,philipWendland/OpenSC,gentoo/OpenSC,marschap/pkg-opensc,jpki/OpenSC,carlhoerberg/OpenSC,dengert/OpenSC,dirkx/OpenSC,UIKit0/OpenSC,jpki/OpenSC,germanblanco/OpenSC,carlhoerberg/OpenSC,aobaid/OpenSC,frankmorgner/OpenSC,hhonkanen/OpenSC,tidatida/OpenSC,mouse07410/OpenSC,0x7678/OpenSC,OpenSC/OpenSC,martinpaljak/OpenSC,financeX/OpenSC,adminmt/OpenSC,l1k/OpenSC,nmav/OpenSC,CardContact/OpenSC,frankmorgner/OpenSC,hhonkanen/OpenSC,velter/OpenSC,0x7678/myOpenSC,rickyepoderi/OpenSC,ieugen/OpenSC,mouse07410/OpenSC,UIKit0/OpenSC,dirkx/OpenSC.tokend,LudovicRousseau/OpenSC,dirkx/OpenSC,metsma/OpenSC,dirkx/OpenSC.tokend,aobaid/OpenSC,AktivCo/OpenSC,financeX/OpenSC,kasparsd/opensc-latvia-id,marschap/pkg-opensc,LudovicRousseau/OpenSC,gentoo/OpenSC