summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHwankyu Jhun <h.jhun@samsung.com>2024-01-11 20:00:59 +0900
committerHwankyu Jhun <h.jhun@samsung.com>2024-01-12 09:44:51 +0900
commit2423bd802acf21d4153c82f234acb9698e0f02bd (patch)
tree9ac0a2d99097cb7728d7c57378a4504a2baac8d5
parentf513f14290a386064adf98fe45b37d86c26089b1 (diff)
downloadaul-1-2423bd802acf21d4153c82f234acb9698e0f02bd.tar.gz
aul-1-2423bd802acf21d4153c82f234acb9698e0f02bd.tar.bz2
aul-1-2423bd802acf21d4153c82f234acb9698e0f02bd.zip
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 <h.jhun@samsung.com>
-rw-r--r--src/aul_sock.cc12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/aul_sock.cc b/src/aul_sock.cc
index f8cc053f..23903a3d 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,