From 2423bd802acf21d4153c82f234acb9698e0f02bd Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 11 Jan 2024 20:00:59 +0900 Subject: [PATCH] Fix fd leak If the Send() returns an error, the aul library should close the file descriptor when the socket option is not AUL_SOCK_ASYNC. Change-Id: I84119f6af4e0643d688f6c81a86de6491ba5a7af Signed-off-by: Hwankyu Jhun --- src/aul_sock.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/aul_sock.cc b/src/aul_sock.cc index f8cc053..23903a3 100644 --- a/src/aul_sock.cc +++ b/src/aul_sock.cc @@ -186,8 +186,8 @@ int SendAndReceive(ClientSocket* client, int cmd, unsigned char* data, int ret = client->Send(parcel.GetData(), parcel.GetDataSize()); if (ret != 0 || opt & AUL_SOCK_NOREPLY) { - if (opt & AUL_SOCK_ASYNC) - client->RemoveFd(); + if (!(opt & AUL_SOCK_ASYNC)) + client->Close(); return ret; } @@ -206,7 +206,13 @@ int SendAndReceive(ClientSocket* client, int cmd, unsigned char* data, int SendAndReceive(int fd, int cmd, unsigned char* data, int datalen, int opt) { ClientSocket client(fd); - return SendAndReceive(&client, cmd, data, datalen, opt); + int ret = SendAndReceive(&client, cmd, data, datalen, opt); + if (ret < 0) { + if (opt & AUL_SOCK_ASYNC) + client.RemoveFd(); + } + + return ret; } int SendAndReceive(int pid, uid_t uid, int cmd, unsigned char* data, -- 2.7.4