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.
diff --git a/src/main/c/org_apache_activemq_artemis_jlibaio_LibaioContext.c b/src/main/c/org_apache_activemq_artemis_jlibaio_LibaioContext.c
index e70edee..1cf9a17 100644
--- a/src/main/c/org_apache_activemq_artemis_jlibaio_LibaioContext.c
+++ b/src/main/c/org_apache_activemq_artemis_jlibaio_LibaioContext.c
@@ -374,7 +374,7 @@
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 @@
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 @@
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 @@
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;
}