summaryrefslogtreecommitdiff
path: root/src/sss_client/common.c
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2010-12-15 15:06:39 +0100
committerStephen Gallagher <sgallagh@redhat.com>2010-12-15 11:06:50 -0500
commit4555f34c78d16746b0856db928e55eb92c9ee2a4 (patch)
treecd31cfa7183f5477c27227299827df87c724e57e /src/sss_client/common.c
parentad6c0f29d78f2ce5d84d5e3d80e56152eac1b9d4 (diff)
downloadsssd-4555f34c78d16746b0856db928e55eb92c9ee2a4.tar.gz
sssd-4555f34c78d16746b0856db928e55eb92c9ee2a4.tar.bz2
sssd-4555f34c78d16746b0856db928e55eb92c9ee2a4.zip
Fix another possible memory leak in sss_nss_recv_rep()
https://fedorahosted.org/sssd/ticket/723
Diffstat (limited to 'src/sss_client/common.c')
-rw-r--r--src/sss_client/common.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/sss_client/common.c b/src/sss_client/common.c
index 905c0df4..20def9be 100644
--- a/src/sss_client/common.c
+++ b/src/sss_client/common.c
@@ -175,8 +175,9 @@ static enum nss_status sss_nss_recv_rep(enum sss_cli_command cmd,
{
uint32_t header[4];
size_t datarecv;
- uint8_t *buf;
+ uint8_t *buf = NULL;
int len;
+ int ret;
header[0] = SSS_NSS_HEADER_SIZE; /* unitl we know the real lenght */
header[1] = 0;
@@ -228,7 +229,8 @@ static enum nss_status sss_nss_recv_rep(enum sss_cli_command cmd,
}
if (*errnop) {
sss_cli_close_socket();
- return NSS_STATUS_UNAVAIL;
+ ret = NSS_STATUS_UNAVAIL;
+ goto failed;
}
errno = 0;
@@ -259,7 +261,8 @@ static enum nss_status sss_nss_recv_rep(enum sss_cli_command cmd,
sss_cli_close_socket();
*errnop = errno;
- return NSS_STATUS_UNAVAIL;
+ ret = NSS_STATUS_UNAVAIL;
+ goto failed;
}
datarecv += res;
@@ -273,24 +276,28 @@ static enum nss_status sss_nss_recv_rep(enum sss_cli_command cmd,
sss_cli_close_socket();
*errnop = header[2];
if (*errnop == EAGAIN) {
- return NSS_STATUS_TRYAGAIN;
+ ret = NSS_STATUS_TRYAGAIN;
+ goto failed;
} else {
- return NSS_STATUS_UNAVAIL;
+ ret = NSS_STATUS_UNAVAIL;
+ goto failed;
}
}
if (header[1] != cmd) {
/* wrong command id */
sss_cli_close_socket();
*errnop = EBADMSG;
- return NSS_STATUS_UNAVAIL;
+ ret = NSS_STATUS_UNAVAIL;
+ goto failed;
}
if (header[0] > SSS_NSS_HEADER_SIZE) {
len = header[0] - SSS_NSS_HEADER_SIZE;
buf = malloc(len);
if (!buf) {
sss_cli_close_socket();
- *errnop = ENOMEM;
- return NSS_STATUS_UNAVAIL;
+ *errnop = ENOMEM;
+ ret = NSS_STATUS_UNAVAIL;
+ goto failed;
}
}
}
@@ -300,6 +307,10 @@ static enum nss_status sss_nss_recv_rep(enum sss_cli_command cmd,
*_buf = buf;
return NSS_STATUS_SUCCESS;
+
+failed:
+ free(buf);
+ return ret;
}
/* this function will check command codes match and returned length is ok */