Skip to contentSkip to conversation

iothread: fix epollfd leak in the process of delIOThread

PATCH Superseded Jie Wang 3 participants 3 messages May 15, 2018 – May 16, 2018

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Jie Wang

author
#0 lore raw

PATCH 1/1 iothread: fix epollfd leak in the process of delIOThread

When we call addIOThread, the epollfd created in aio_context_setup, but not close it in the process of delIOThread, so the epollfd will leak.

---
 iothread.c | 1 +
 1 file changed, 1 insertion(+)
iothread.c +1 -0
index aff1281..23ac0a8 100644
@@ -128,6 +128,7 @@ static void iothread_instance_finalize(Object *obj)
      * GSources first before destroying any GMainContext.
      */
     if (iothread->ctx) {
+        close(iothread->ctx->epollfd);
         aio_context_unref(iothread->ctx);
         iothread->ctx = NULL;
     }
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 23 lines · Jie Wang

When we call addIOThread, the epollfd created in aio_context_setup, but not close it in the process of delIOThread, so the epollfd will leak.

---
 iothread.c | 1 +
 1 file changed, 1 insertion(+)
iothread.c +1 -0
index aff1281..23ac0a8 100644
@@ -128,6 +128,7 @@ static void iothread_instance_finalize(Object *obj)
      * GSources first before destroying any GMainContext.
      */
     if (iothread->ctx) {
+        close(iothread->ctx->epollfd);
         aio_context_unref(iothread->ctx);
         iothread->ctx = NULL;
     }
Signature · 1 line
1.8.3.1

Please add an aio_context_destroy() function in aio-posix.c and call it from aio_context_finalize(). IOThread code should not touch AioContext internals. Also please remember to wrap the close() code in CONFIG_EPOLL_CREATE1. An empty function may need to be added to aio-win32.c, too.

Fam

#2 lore raw
Quoted 19 lines · Fam Zheng
Quoted 18 lines · Jie Wang

When we call addIOThread, the epollfd created in aio_context_setup, but not close it in the process of delIOThread, so the epollfd will leak.

---
 iothread.c | 1 +
 1 file changed, 1 insertion(+)
iothread.c +1 -0
index aff1281..23ac0a8 100644
@@ -128,6 +128,7 @@ static void iothread_instance_finalize(Object *obj)
      * GSources first before destroying any GMainContext.
      */
     if (iothread->ctx) {
+        close(iothread->ctx->epollfd);
         aio_context_unref(iothread->ctx);
Quoted 8 lines
Quoted 5 lines
iothread.c +0 -0
         iothread->ctx = NULL;
     }
Signature · 1 line
1.8.3.1

Please add an aio_context_destroy() function in aio-posix.c and call it from aio_context_finalize(). IOThread code should not touch AioContext internals.

I believe Fam means aio_ctx_finalize().

Quoted 2 lines

Also please remember to wrap the close() code in CONFIG_EPOLL_CREATE1. An empty function may need to be added to aio-win32.c, too.

Agreed.

Signature · 1 line
Peter Xu