From 98f8903e20bc7a5ebff92e62e3cf5641c3593f5d Mon Sep 17 00:00:00 2001 From: Karl-Heinz Zimmer Date: Thu, 13 Dec 2001 15:13:09 +0000 Subject: [PATCH] improce memory handling --- trunk/gpgmeplug/gpgmeplug.c | 62 +++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/trunk/gpgmeplug/gpgmeplug.c b/trunk/gpgmeplug/gpgmeplug.c index 1fc8801..42b8438 100644 --- a/trunk/gpgmeplug/gpgmeplug.c +++ b/trunk/gpgmeplug/gpgmeplug.c @@ -951,7 +951,7 @@ bool encryptMessage( const char* cleartext, // untrusted key (oder gar keiner) gefunden wurde, verweigert gpg // das signieren. } - + gpgme_release (ctx); return bOk; @@ -966,11 +966,12 @@ bool decryptMessage( const char* ciphertext, const char** cleartext, const char* certificate ) { - GpgmeCtx ctx; - GpgmeData gCiphertext, gPlaintext; - size_t rCLen; - char* rCiph = 0; - bool bOk = false; + GpgmeCtx ctx; + GpgmeError err; + GpgmeData gCiphertext, gPlaintext; + size_t rCLen = 0; + char* rCiph = 0; + bool bOk = false; @@ -984,6 +985,19 @@ bool decryptMessage( const char* ciphertext, struct passphrase_cb_info_s info; + + + + if( !ciphertext ) + return false; + + err = gpgme_new (&ctx); + gpgme_set_protocol (ctx, GPGMEPLUG_PROTOCOL); + + + + + /* temporary code!! @@ -999,28 +1013,28 @@ bool decryptMessage( const char* ciphertext, - gpgme_new( &ctx ); - gpgme_data_new_from_mem( &gCiphertext, ciphertext, - 1+strlen( ciphertext ), 1 ); - gpgme_data_new( &gPlaintext ); - gpgme_op_decrypt( ctx, gCiphertext, gPlaintext ); - gpgme_data_release( gCiphertext ); + gpgme_data_new_from_mem( &gCiphertext, ciphertext, + 1+strlen( ciphertext ), 1 ); + gpgme_data_new( &gPlaintext ); - rCiph = gpgme_data_release_and_get_mem( gPlaintext, &rCLen ); + gpgme_op_decrypt( ctx, gCiphertext, gPlaintext ); + gpgme_data_release( gCiphertext ); - *cleartext = malloc( rCLen + 1 ); - if( *cleartext ) { - if( rCLen ) { - bOk = true; - strncpy((char*)*cleartext, rCiph, rCLen ); - } - ((char*)(*cleartext))[rCLen] = 0; - } + rCiph = gpgme_data_release_and_get_mem( gPlaintext, &rCLen ); - free( rCiph ); - gpgme_release( ctx ); - return bOk; + *cleartext = malloc( rCLen + 1 ); + if( *cleartext ) { + if( rCLen ) { + bOk = true; + strncpy((char*)*cleartext, rCiph, rCLen ); + } + ((char*)(*cleartext))[rCLen] = 0; + } + + free( rCiph ); + gpgme_release( ctx ); + return bOk; } bool decryptAndCheckMessage( const char* ciphertext, -- 2.26.2