Fix fd leak 04/279604/2
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 12 Aug 2022 06:57:04 +0000 (15:57 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Fri, 12 Aug 2022 07:47:22 +0000 (07:47 +0000)
When IO error occurs, AUL has to close the file descriptor and release
the io job resource of aul worker.

Change-Id: Ic612531f3a2fa53efa9fe55556b770369731769c
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/aul_launch.c
src/aul_worker.c
src/aul_worker.h

index 78120d0..18dbe8a 100644 (file)
@@ -113,6 +113,9 @@ static void __destroy_client_channel(gpointer data)
        g_rec_mutex_unlock(&channel->mutex);
        g_rec_mutex_clear(&channel->mutex);
 
+       if (channel->fd > -1)
+               close(channel->fd);
+
        free(channel);
 }
 
@@ -545,9 +548,10 @@ static bool __received_event_cb(int fd, int condition, void *user_data)
 
        if (condition & (AUL_IO_HUP | AUL_IO_ERR | AUL_IO_NVAL)) {
                _E("IO error occurred. condition(%d), fd(%d)", condition, fd);
+               aul_worker_remove_io_job(worker, fd);
                __remove_client_channel(channel);
                __destroy_client_channel(channel);
-               return false;
+               return true;
        }
 
        g_rec_mutex_lock(&channel->mutex);
index 3593bb2..6a9137c 100644 (file)
@@ -286,6 +286,34 @@ int aul_worker_add_io_job(aul_worker_h handle, const char *job_name,
        return AUL_R_OK;
 }
 
+void aul_worker_remove_io_job(aul_worker_h handle, int fd)
+{
+       struct aul_worker_s *worker = handle;
+       struct job_s *job;
+       GList *iter;
+
+       if (worker == NULL || fd < 0) {
+               _E("Invalid parameter");
+               return;
+       }
+
+       g_mutex_lock(&worker->mutex);
+       iter = worker->jobs;
+       while (iter != NULL) {
+               job = iter->data;
+               iter = g_list_next(iter);
+               if (job->channel == NULL)
+                       continue;
+
+               if (g_io_channel_unix_get_fd(job->channel) == fd) {
+                       worker->jobs = g_list_remove(worker->jobs, job);
+                       __destroy_job(job);
+                       break;
+               }
+       }
+       g_mutex_unlock(&worker->mutex);
+}
+
 void aul_worker_destroy(aul_worker_h handle)
 {
        struct aul_worker_s *worker = (struct aul_worker_s *)handle;
index c4a1c10..afdd79a 100644 (file)
@@ -40,6 +40,8 @@ int aul_worker_add_io_job(aul_worker_h handle, const char *job_name,
                int fd, int condition, aul_worker_io_job_cb callback,
                void *user_data);
 
+void aul_worker_remove_io_job(aul_worker_h handle, int fd);
+
 int aul_worker_add_anr_timer(aul_worker_h handle, int cmd);
 
 int aul_worker_remove_anr_timer(aul_worker_h handle);