aboutsummaryrefslogtreecommitdiff
path: root/tests/echo_srv.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2014-04-10 10:40:32 +0200
committerAndreas Schneider <asn@samba.org>2014-04-14 15:28:59 +0200
commit3786fdc51b18b74411a4d5cca9af2aa3ff250505 (patch)
tree107429c47c8ef69031f96b884572ea9a698bb101 /tests/echo_srv.c
parentf165d65e82eaaf139a89cd8b3f58fbe60f8cbecd (diff)
downloadsocket_wrapper-3786fdc51b18b74411a4d5cca9af2aa3ff250505.tar.gz
socket_wrapper-3786fdc51b18b74411a4d5cca9af2aa3ff250505.tar.xz
socket_wrapper-3786fdc51b18b74411a4d5cca9af2aa3ff250505.zip
echo_srv: Fix resource leak of fd in pidfile().
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jakub Hrozek <jhrozek@redhat.com> Reviewed-by: Simo Sorce <idra@samba.org>
Diffstat (limited to 'tests/echo_srv.c')
-rw-r--r--tests/echo_srv.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/tests/echo_srv.c b/tests/echo_srv.c
index 4c65d19..e7e6e6c 100644
--- a/tests/echo_srv.c
+++ b/tests/echo_srv.c
@@ -53,7 +53,9 @@ static int pidfile(const char *path)
{
int err;
int fd;
- char pid_str[32];
+ char pid_str[32] = { 0 };
+ ssize_t nwritten;
+ size_t len;
fd = open(path, O_RDONLY, 0644);
err = errno;
@@ -70,9 +72,14 @@ static int pidfile(const char *path)
return err;
}
- memset(pid_str, 0, sizeof(pid_str));
snprintf(pid_str, sizeof(pid_str) -1, "%u\n", (unsigned int) getpid());
- write(fd, pid_str, strlen(pid_str));
+ len = strlen(pid_str);
+
+ nwritten = write(fd, pid_str, len);
+ close(fd);
+ if (nwritten != (ssize_t)len) {
+ return EIO;
+ }
return 0;
}