diff options
author | Dean Jansa <djansa@redhat.com> | 2008-08-22 21:04:16 +0000 |
---|---|---|
committer | Nathan Straz <nstraz@redhat.com> | 2008-09-23 09:37:47 -0400 |
commit | f6da9f58ab06baee5f0d521f1c64a6982546c560 (patch) | |
tree | 21f0184599d156b68aa800d2889f204b3baafad9 | |
parent | 54cc78586aec14c714060c2d64837cfe54fdc9eb (diff) | |
download | qarsh-f6da9f58ab06baee5f0d521f1c64a6982546c560.tar.gz qarsh-f6da9f58ab06baee5f0d521f1c64a6982546c560.tar.xz qarsh-f6da9f58ab06baee5f0d521f1c64a6982546c560.zip |
Plug some memory leaks
-rw-r--r-- | qacp.c | 36 | ||||
-rw-r--r-- | qarsh_packet.c | 8 | ||||
-rw-r--r-- | sockutil.c | 6 |
3 files changed, 37 insertions, 13 deletions
@@ -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; } diff --git a/qarsh_packet.c b/qarsh_packet.c index cdc87ec..837b58f 100644 --- a/qarsh_packet.c +++ b/qarsh_packet.c @@ -1,5 +1,5 @@ /* - * 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 @@ -420,9 +420,13 @@ get_xpath_string(xmlXPathContextPtr ctxt, const char *xpath_query) xmlNodePtr make_param(char *name, char *value) { + xmlChar *xstr; + xmlNodePtr param = xmlNewNode(NULL, QP_PARAM_XML); xmlNewProp(param, QP_NAME_XML, (xmlChar *)name); - xmlNodeSetContent(param, xmlEncodeSpecialChars(NULL, (xmlChar *)value)); + xstr = xmlEncodeSpecialChars(NULL, (xmlChar *)value); + xmlNodeSetContent(param, xstr); + xmlFree(xstr); return param; } @@ -1,5 +1,5 @@ /* - * 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 @@ -143,9 +143,7 @@ send_packet(int fd, struct qa_packet *qp) char *packetbuf; int packetsize; ssize_t ret; - - packetbuf = malloc(QARSH_MAX_PACKET_SIZE); - memset(packetbuf, 0, QARSH_MAX_PACKET_SIZE); + packetbuf = qptostr(qp, &packetbuf, &packetsize); ret = write(fd, packetbuf, packetsize); |