Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 0FEB1200B32 for ; Thu, 23 Jun 2016 09:21:18 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 0E873160A59; Thu, 23 Jun 2016 07:21:18 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 5636A160A58 for ; Thu, 23 Jun 2016 09:21:17 +0200 (CEST) Received: (qmail 21681 invoked by uid 500); 23 Jun 2016 07:21:16 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 21660 invoked by uid 99); 23 Jun 2016 07:21:16 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Jun 2016 07:21:16 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 3A24C2C14E1 for ; Thu, 23 Jun 2016 07:21:16 +0000 (UTC) Date: Thu, 23 Jun 2016 07:21:16 +0000 (UTC) From: "Xianda Ke (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (CRYPTO-89) more robust native code to eliminate memory leak MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Thu, 23 Jun 2016 07:21:18 -0000 [ https://issues.apache.org/jira/browse/CRYPTO-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15345950#comment-15345950 ] Xianda Ke commented on CRYPTO-89: --------------------------------- {code:title=OpensslNative.c} Java_org_apache_commons_crypto_cipher_OpensslNative_init () { // ugly & hard to be understood // return 0, the context pointer will be reset as NULL, and the context has not change to be deallocated. // memory leak! jbyte *jIv = (*env)->GetByteArrayElements(env, iv, NULL); if (jIv == NULL) { (*env)->ReleaseByteArrayElements(env, key, jKey, 0); THROW(env, "java/lang/InternalError", "Cannot get bytes array for iv."); return (jlong)0; } // potential memory leak! if (!(alg == AES_CTR || alg == AES_CBC)) { THROW(env, "java/security/NoSuchAlgorithmException", "The algorithm is not supported."); return (jlong)0; } // Error is not handled if (padding == NOPADDING) { dlsym_EVP_CIPHER_CTX_set_padding(context, 0); } else if (padding == PKCS5PADDING) { dlsym_EVP_CIPHER_CTX_set_padding(context, 1); } } //... {code} > more robust native code to eliminate memory leak > ------------------------------------------------ > > Key: CRYPTO-89 > URL: https://issues.apache.org/jira/browse/CRYPTO-89 > Project: Commons Crypto > Issue Type: Bug > Reporter: Xianda Ke > Assignee: Xianda Ke > > currently, when handling error in the native code, some resource allocated is not deallocated. > {code} > input_bytes = (unsigned char *) (*env)->GetByteArrayElements(env, input, 0); //in some case, it is not deallocated > {code} > the byte array may accupy lots of memory. this can cause serious memory leak in the long-running server -- This message was sent by Atlassian JIRA (v6.3.4#6332)