Fix a bug referenced a dangling pointer 04/277704/1
authorUnsung Lee <unsung.lee@samsung.com>
Tue, 12 Jul 2022 08:00:37 +0000 (17:00 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Tue, 12 Jul 2022 08:02:14 +0000 (17:02 +0900)
Change-Id: I9db99145b0b07c077e86eb972d4a511f5288e203
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/common/fd-handler.c
src/resource-limiter/memory/lowmem-handler.h
src/resource-limiter/memory/lowmem-limit.c
src/resource-optimizer/cpu/cpu-boosting.c

index 6855d98..b950a21 100644 (file)
@@ -59,7 +59,9 @@ int remove_fd_read_handler(fd_handler_h *handler)
        if (h->ch)
                g_io_channel_unref(h->ch);
 
-       *(h->handler_p) = NULL;
+       if (h->handler_p != NULL)
+               *(h->handler_p) = NULL;
+
        free(h);
 
        return 0;
@@ -141,8 +143,8 @@ int add_fd_read_handler(int fd,
        h->ch = ch;
        h->id = id;
        h->handler_p = handler;
-
-       *handler = h;
+       if (handler != NULL)
+               *handler = h;
 
        return 0;
 }
index 504a169..154ff12 100644 (file)
@@ -60,7 +60,6 @@ struct task_info {
 };
 
 struct memory_limit_event {
-       fd_handler_h fdh;
        int fd;
        unsigned long long threshold_bytes;             /* byte */
        char *path;
index 7b14731..e9e5722 100644 (file)
@@ -271,7 +271,6 @@ int lowmem_reassign_limit(const char *dir,
                unsigned long long limit_bytes, enum proc_action action)
 {
        int fd;
-       fd_handler_h fdh = NULL;
        gpointer hash_entry;
        struct memory_limit_event *mle = NULL;
        char buf[MAX_DEC_SIZE(int)] = {0};
@@ -339,8 +338,7 @@ int lowmem_reassign_limit(const char *dir,
                }
                mle->action = action;
                mle->threshold_bytes = limit_bytes;
-               add_fd_read_handler(fd, memory_action_cb, mle->path, NULL, &fdh);
-               mle->fdh = fdh;
+               add_fd_read_handler(fd, memory_action_cb, mle->path, NULL, NULL);
                g_hash_table_insert(memory_limit_hash, (gpointer)mle->path,
                                (gpointer)mle);
 
index 3f94c15..30a59bb 100644 (file)
@@ -640,7 +640,6 @@ bool cpu_boosting_connect_from_client(int fd, void *data)
 {
        int ret;
        int master_sock = fd;
-       static fd_handler_h handler;
        socklen_t len;
        struct sockaddr_un cli = { 0 };
 
@@ -657,7 +656,7 @@ bool cpu_boosting_connect_from_client(int fd, void *data)
 
        /* Add event handler to receive data from the client */
        ret = add_fd_read_handler(new_sock, cpu_boosting_recv_from_client,
-                       NULL, NULL, &handler);
+                       NULL, NULL, NULL);
        if (ret < 0) {
                _E("[CPU-BOOSTING] Failed to add event handler of (sock = %d)", new_sock);
                close(new_sock);