summaryrefslogtreecommitdiffstats
path: root/qacp.c
diff options
context:
space:
mode:
authorDean Jansa <djansa@redhat.com>2008-08-22 21:04:16 +0000
committerNathan Straz <nstraz@redhat.com>2008-09-23 09:37:47 -0400
commitf6da9f58ab06baee5f0d521f1c64a6982546c560 (patch)
tree21f0184599d156b68aa800d2889f204b3baafad9 /qacp.c
parent54cc78586aec14c714060c2d64837cfe54fdc9eb (diff)
downloadqarsh-f6da9f58ab06baee5f0d521f1c64a6982546c560.tar.gz
qarsh-f6da9f58ab06baee5f0d521f1c64a6982546c560.tar.xz
qarsh-f6da9f58ab06baee5f0d521f1c64a6982546c560.zip
Plug some memory leaks
Diffstat (limited to 'qacp.c')
-rw-r--r--qacp.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/qacp.c b/qacp.c
index 7386092..3d3e68b 100644
--- a/qacp.c
+++ b/qacp.c
@@ -3,7 +3,7 @@
*
* Copy a file to, or from, server.
*
- * Copyright © 2005-2006 Red Hat, Inc. All rights reserved.
+ * Copyright © 2005-20068 Red Hat, Inc. All rights reserved.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions of the
@@ -80,8 +80,11 @@ set_remote_user(char *user, char *group)
fprintf(stderr, "Remote side failed, %s\n",
qp->qp_returncode.qp_strerror);
close(qacp_fd);
+ qpfree(qp);
exit(125);
}
+
+ qpfree(qp);
}
@@ -204,9 +207,12 @@ sendone_failure:
fprintf(stderr, "Remote side failed, %s\n",
qp->qp_returncode.qp_strerror);
close(qacp_fd);
+ qpfree(qp);
exit(125);
}
+ qpfree(qp);
+
if (!quiet) {
printf("%-30.30s -> %s:%s\n", srcfile, host, destfile);
}
@@ -473,7 +479,7 @@ recvfiles(char **argv, int argc, int fileidx, short recursive)
int
sendfiles(char **argv, int argc, int fileidx, short recursive)
{
- char *cp;
+ char *cp, *cp2;
char *rhost = NULL;
char *ruser = NULL;
char *rgrp = NULL;
@@ -512,6 +518,7 @@ sendfiles(char **argv, int argc, int fileidx, short recursive)
if (!(pw = getpwuid(getuid()))) {
fprintf(stderr, "qacp: unknown user id.\n");
+ free(rhost);
return -1;
}
@@ -528,15 +535,18 @@ sendfiles(char **argv, int argc, int fileidx, short recursive)
fprintf(stderr, "Could not connect to %s:%d, %d: %s\n",
rhost, QARSHD_CONTROL_PORT, errno, strerror(errno));
}
+
+ free(rhost);
return -1;
}
set_remote_user(ruser, rgrp);
cp = strdup(argv[argc-1]);
- cp = strchr(argv[argc-1], ':');
- cp++;
- rmtpath = strdup(cp);
+ cp2 = strchr(cp, ':');
+ cp2++;
+ rmtpath = strdup(cp2);
+ free(cp);
rstatp = qacp_rstat(rmtpath, &rstaterrno);
@@ -568,25 +578,37 @@ sendfiles(char **argv, int argc, int fileidx, short recursive)
free(tmpstr);
rstatp = qacp_rstat(rdnp, &rstaterrno);
+ free(rdnp);
+
if (rstatp) {
/* Ok, the dir exists, i.e. rmtpath is /tmp/foo
* and the first rstat was an error. Now we know
* that /tmp exists, we leave destpath == rmtpath.
*/
destpath = strdup(rmtpath);
+ free(rstatp->qp_path);
+ free(rstatp);
} else {
fprintf(stderr, "%s:%s - %s\n", rhost, rmtpath,
strerror(rstaterrno));
+ free(rhost);
return -1;
}
}
qacp_sendonefile(rhost, argv[file], destpath);
-
+
free(lbnp);
free(destpath);
+ free(rmtpath);
}
-
+
+ if (rstatp) {
+ free(rstatp->qp_path);
+ free(rstatp);
+ }
+ free(ruser);
+
return 0;
}