diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2022-08-12 15:57:04 +0900 |
---|---|---|
committer | Hwankyu Jhun <h.jhun@samsung.com> | 2022-09-16 06:51:29 +0000 |
commit | 08c48469b7ff85309eb9c6a80011b7c4aee17bbd (patch) | |
tree | 9c910abfb315f61ffcfb5277adcb7c119605708f | |
parent | a5db896122321cb9d289ea076c5e9b2179e5bab7 (diff) | |
download | aul-1-08c48469b7ff85309eb9c6a80011b7c4aee17bbd.tar.gz aul-1-08c48469b7ff85309eb9c6a80011b7c4aee17bbd.tar.bz2 aul-1-08c48469b7ff85309eb9c6a80011b7c4aee17bbd.zip |
Fix fd leak
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>
-rw-r--r-- | src/aul_launch.c | 6 | ||||
-rw-r--r-- | src/aul_worker.c | 28 | ||||
-rw-r--r-- | src/aul_worker.h | 2 |
3 files changed, 35 insertions, 1 deletions
diff --git a/src/aul_launch.c b/src/aul_launch.c index 2a95ed43..e4935ce9 100644 --- a/src/aul_launch.c +++ b/src/aul_launch.c @@ -109,6 +109,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); } @@ -498,9 +501,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); diff --git a/src/aul_worker.c b/src/aul_worker.c index 3593bb2c..6a9137cd 100644 --- a/src/aul_worker.c +++ b/src/aul_worker.c @@ -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; diff --git a/src/aul_worker.h b/src/aul_worker.h index c4a1c108..afdd79ad 100644 --- a/src/aul_worker.h +++ b/src/aul_worker.h @@ -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); |