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.
This commit is contained in:
Otavio Rodolfo Piske 2019-01-30 14:32:47 +01:00 committed by Clebert Suconic
parent 6dafedb6af
commit 24b3f08c88
1 changed files with 5 additions and 4 deletions

View File

@ -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;
}