From 4bef93eb16938efae6dd110790f5f57c76eb9117 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Tue, 8 Dec 2009 10:58:01 -0500 Subject: Add allocation error check --- server/util/server.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'server') diff --git a/server/util/server.c b/server/util/server.c index 3a84c70d7..977deaeb2 100644 --- a/server/util/server.c +++ b/server/util/server.c @@ -111,7 +111,10 @@ int pidfile(const char *path, const char *name) int fd; int ret, err; - asprintf(&file, "%s/%s.pid", path, name); + file = talloc_asprintf(NULL, "%s/%s.pid", path, name); + if (!file) { + return ENOMEM; + } fd = open(file, O_RDONLY, 0644); err = errno; @@ -129,25 +132,25 @@ int pidfile(const char *path, const char *name) /* succeeded in signaling the process -> another sssd process */ if (ret == 0) { close(fd); - free(file); + talloc_free(file); return EEXIST; } if (ret != 0 && errno != ESRCH) { err = errno; close(fd); - free(file); + talloc_free(file); return err; } } } - /* notihng in the file or no process */ + /* nothing in the file or no process */ close(fd); unlink(file); } else { if (err != ENOENT) { - free(file); + talloc_free(file); return err; } } @@ -155,10 +158,10 @@ int pidfile(const char *path, const char *name) fd = open(file, O_CREAT | O_WRONLY | O_EXCL, 0644); err = errno; if (fd == -1) { - free(file); + talloc_free(file); return err; } - free(file); + talloc_free(file); memset(pid_str, 0, sizeof(pid_str)); snprintf(pid_str, sizeof(pid_str) -1, "%u\n", (unsigned int) getpid()); -- cgit