geo-replication: coverity resource leak fixes
Change-Id: I5739e9c9ae6fe78a6defb640d630e5f918ac1295 Signed-off-by: Amar Tumballi <amarts@redhat.com> BUG: 789278 Reviewed-on: http://review.gluster.com/3266 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
This commit is contained in:
committed by
Anand Avati
parent
53a09f49ab
commit
17b0814243
@ -166,21 +166,28 @@ find_gsyncd (pid_t pid, pid_t ppid, char *name, void *data)
|
||||
pid_t *pida = (pid_t *)data;
|
||||
|
||||
if (ppid != pida[0])
|
||||
return 0;
|
||||
goto out;
|
||||
|
||||
ret = gf_asprintf (&p, PROC"/%d/cmdline", pid);
|
||||
if (ret == -1) {
|
||||
fprintf (stderr, "out of memory\n");
|
||||
return -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
fd = open (p, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return 0;
|
||||
goto out;
|
||||
|
||||
ret = read (fd, buf, sizeof (buf));
|
||||
close (fd);
|
||||
if (ret == -1)
|
||||
return 0;
|
||||
|
||||
if (ret == -1) {
|
||||
ret = 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (zeros = 0, p = buf; zeros < 2 && p < buf + ret; p++)
|
||||
zeros += !*p;
|
||||
|
||||
@ -201,12 +208,18 @@ find_gsyncd (pid_t pid, pid_t ppid, char *name, void *data)
|
||||
if (ret == 1) {
|
||||
if (pida[1] != -1) {
|
||||
fprintf (stderr, GSYNCD_PY" sibling is not unique");
|
||||
return -1;
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
pida[1] = pid;
|
||||
}
|
||||
|
||||
return 0;
|
||||
ret = 0;
|
||||
out:
|
||||
if (p)
|
||||
GF_FREE (p);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
@ -242,6 +255,8 @@ invoke_rsync (int argc, char **argv)
|
||||
}
|
||||
if (strcmp (name, "sshd") == 0)
|
||||
break;
|
||||
GF_FREE (name);
|
||||
name = NULL;
|
||||
}
|
||||
/* look up "ssh-sibling" gsyncd */
|
||||
pida[0] = pid;
|
||||
@ -269,10 +284,22 @@ invoke_rsync (int argc, char **argv)
|
||||
|
||||
execvp (RSYNC, argv);
|
||||
|
||||
if (p)
|
||||
GF_FREE (p);
|
||||
|
||||
if (name)
|
||||
GF_FREE (name);
|
||||
|
||||
fprintf (stderr, "exec of "RSYNC" failed\n");
|
||||
return 127;
|
||||
|
||||
error:
|
||||
if (p)
|
||||
GF_FREE (p);
|
||||
|
||||
if (name)
|
||||
GF_FREE (name);
|
||||
|
||||
fprintf (stderr, "disallowed "RSYNC" invocation\n");
|
||||
return 1;
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ pidinfo (pid_t pid, char **name)
|
||||
char buf[NAME_MAX * 2] = {0,};
|
||||
FILE *f = NULL;
|
||||
char *p = NULL;
|
||||
char *free_p = NULL;
|
||||
int ret = 0;
|
||||
|
||||
ret = gf_asprintf (&p, PROC"/%d/status", pid);
|
||||
@ -45,8 +46,11 @@ pidinfo (pid_t pid, char **name)
|
||||
goto oom;
|
||||
|
||||
f = fopen (p, "r");
|
||||
if (!f)
|
||||
if (!f) {
|
||||
GF_FREE (p);
|
||||
return -1;
|
||||
}
|
||||
free_p = p;
|
||||
|
||||
if (name)
|
||||
*name = NULL;
|
||||
@ -81,17 +85,21 @@ pidinfo (pid_t pid, char **name)
|
||||
pid = -1;
|
||||
|
||||
out:
|
||||
if (free_p)
|
||||
GF_FREE (free_p);
|
||||
fclose (f);
|
||||
return pid;
|
||||
|
||||
oom:
|
||||
if (free_p)
|
||||
GF_FREE (free_p);
|
||||
fclose (f);
|
||||
fprintf (stderr, "out of memory\n");
|
||||
return -2;
|
||||
}
|
||||
|
||||
int
|
||||
prociter (int (*proch) (pid_t pid, pid_t ppid, char *name, void *data),
|
||||
prociter (int (*proch) (pid_t pid, pid_t ppid, char *tmpname, void *data),
|
||||
void *data)
|
||||
{
|
||||
char *name = NULL;
|
||||
@ -102,23 +110,38 @@ prociter (int (*proch) (pid_t pid, pid_t ppid, char *name, void *data),
|
||||
int ret = 0;
|
||||
|
||||
d = opendir (PROC);
|
||||
if (!d) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
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: return -1;
|
||||
case -2: closedir (d); return -1;
|
||||
}
|
||||
ret = proch (pid, ppid, name, data);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (ret) {
|
||||
goto out;
|
||||
}
|
||||
GF_FREE (name);
|
||||
name = NULL;
|
||||
}
|
||||
}
|
||||
if (errno) {
|
||||
fprintf (stderr, "failed to traverse "PROC" (%s)\n",
|
||||
strerror (errno));
|
||||
return -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
return 0;
|
||||
ret = 0;
|
||||
out:
|
||||
if (d)
|
||||
closedir (d);
|
||||
|
||||
if (name)
|
||||
GF_FREE (name);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user