You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2019/02/22 15:11:34 UTC

[activemq-artemis] 03/05: ARTEMIS-2260 Fix an incorrect cleanup of the AIO I/O context.

This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit 24b3f08c881eb972d63e1f5f8918e9a80d2480b9
Author: Otavio Rodolfo Piske <op...@redhat.com>
AuthorDate: Wed Jan 30 14:32:47 2019 +0100

    ARTEMIS-2260 Fix an incorrect cleanup of the AIO I/O context.
    
    Since the context is initialized on the stack, calling free on it is
    incorrect and can lead to memory corruption. This replaces the cleanup
    routines w/ io_queue_release which is the appropriate way to cleanup the
    context.
---
 .../main/c/org_apache_activemq_artemis_jlibaio_LibaioContext.c   | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/artemis-native/src/main/c/org_apache_activemq_artemis_jlibaio_LibaioContext.c b/artemis-native/src/main/c/org_apache_activemq_artemis_jlibaio_LibaioContext.c
index 9e10c9d..ac49210 100644
--- a/artemis-native/src/main/c/org_apache_activemq_artemis_jlibaio_LibaioContext.c
+++ b/artemis-native/src/main/c/org_apache_activemq_artemis_jlibaio_LibaioContext.c
@@ -374,7 +374,7 @@ JNIEXPORT jobject JNICALL Java_org_apache_activemq_artemis_jlibaio_LibaioContext
     int res = io_queue_init(queueSize, &libaioContext);
     if (res) {
         // Error, so need to release whatever was done before
-        free(libaioContext);
+        io_queue_release(libaioContext);
 
         throwRuntimeExceptionErrorNo(env, "Cannot initialize queue:", res);
         return NULL;
@@ -407,7 +407,7 @@ JNIEXPORT jobject JNICALL Java_org_apache_activemq_artemis_jlibaio_LibaioContext
     res = pthread_mutex_init(&(theControl->iocbLock), 0);
     if (res) {
         free(theControl);
-        free(libaioContext);
+        io_queue_release(libaioContext);
         throwRuntimeExceptionErrorNo(env, "Can't initialize mutext:", res);
         return NULL;
     }
@@ -415,7 +415,7 @@ JNIEXPORT jobject JNICALL Java_org_apache_activemq_artemis_jlibaio_LibaioContext
     res = pthread_mutex_init(&(theControl->pollLock), 0);
     if (res) {
         free(theControl);
-        free(libaioContext);
+        io_queue_release(libaioContext);
         throwRuntimeExceptionErrorNo(env, "Can't initialize mutext:", res);
         return NULL;
     }
@@ -423,7 +423,8 @@ JNIEXPORT jobject JNICALL Java_org_apache_activemq_artemis_jlibaio_LibaioContext
     struct io_event * events = (struct io_event *)malloc(sizeof(struct io_event) * (size_t)queueSize);
     if (events == NULL) {
         free(theControl);
-        free(libaioContext);
+        io_queue_release(libaioContext);
+
         throwRuntimeExceptionErrorNo(env, "Can't initialize mutext (not enough memory for the events member): ", res);
         return NULL;
     }