diff options
author | Csaba Henk <csaba@redhat.com> | 2012-05-16 15:40:47 +0530 |
---|---|---|
committer | Vijay Bellur <vijay@gluster.com> | 2012-05-18 00:45:15 -0700 |
commit | 80a2d2752fcc363cba04a7421451cbe000edd6c5 (patch) | |
tree | 17c7ff44f0ba7c21f5b0409387d8624b22f0d29d /xlators/features/marker/utils/src/procdiggy.c | |
parent | 8c7e1cfdebc6591bbedbe2e1b98b7b3279e6519c (diff) |
geo-rep / gsyncd.c: fix coverity fix
gsyncd wrapper was segfaulting as coverity fix freed
up pointer at wrong place (after it was reused)
Instead of the apporach of the original coverity fix
that added elaborate control flow to hunt down potential
leaks, here we move the code over to static allocations
in place of (the not really necessary) dynamic ones.
Change-Id: Ida3855ff4a4f4371b350d27f858f129ceed51785
BUG: 789278
Signed-off-by: Csaba Henk <csaba@redhat.com>
Reviewed-on: http://review.gluster.com/3345
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'xlators/features/marker/utils/src/procdiggy.c')
-rw-r--r-- | xlators/features/marker/utils/src/procdiggy.c | 59 |
1 files changed, 20 insertions, 39 deletions
diff --git a/xlators/features/marker/utils/src/procdiggy.c b/xlators/features/marker/utils/src/procdiggy.c index 18296a479..0baab966d 100644 --- a/xlators/features/marker/utils/src/procdiggy.c +++ b/xlators/features/marker/utils/src/procdiggy.c @@ -38,20 +38,15 @@ pidinfo (pid_t pid, char **name) { char buf[NAME_MAX * 2] = {0,}; FILE *f = NULL; + char path[PATH_MAX] = {0,}; char *p = NULL; - char *free_p = NULL; int ret = 0; - ret = gf_asprintf (&p, PROC"/%d/status", pid); - if (ret == -1) - goto oom; + sprintf (path, PROC"/%d/status", pid); - f = fopen (p, "r"); - if (!f) { - GF_FREE (p); + f = fopen (path, "r"); + if (!f) return -1; - } - free_p = p; if (name) *name = NULL; @@ -69,8 +64,10 @@ pidinfo (pid_t pid, char **name) if (p) { while (isspace (*++p)); *name = gf_strdup (p); - if (!*name) - goto oom; + if (!*name) { + pid = -2; + goto out; + } continue; } } @@ -86,17 +83,12 @@ pidinfo (pid_t pid, char **name) pid = -1; out: - if (free_p) - GF_FREE (free_p); fclose (f); + if (pid == -1 && name && *name) + GF_FREE (name); + if (pid == -2) + fprintf (stderr, "out of memory\n"); return pid; - - oom: - if (free_p) - GF_FREE (free_p); - fclose (f); - fprintf (stderr, "out of memory\n"); - return -2; } int @@ -111,38 +103,27 @@ prociter (int (*proch) (pid_t pid, pid_t ppid, char *tmpname, void *data), int ret = 0; d = opendir (PROC); - if (!d) { - ret = -1; - goto out; - } + if (!d) + return -1; while (errno = 0, de = readdir (d)) { if (gf_string2int (de->d_name, &pid) != -1 && pid >= 0) { ppid = pidinfo (pid, &name); switch (ppid) { case -1: continue; - case -2: closedir (d); return -1; + case -2: ret = -1; break; } ret = proch (pid, ppid, name, data); - if (ret) { - goto out; - } GF_FREE (name); - name = NULL; + if (ret) + break; } } - if (errno) { + closedir (d); + if (!de && errno) { fprintf (stderr, "failed to traverse "PROC" (%s)\n", strerror (errno)); - goto out; + ret = -1; } - ret = 0; -out: - if (d) - closedir (d); - - if (name) - GF_FREE (name); - return ret; } |