From 3869a299b8716404bc55d000677852b52cef54ef Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 10 Apr 2013 22:16:45 +0000 Subject: ar_next: fix signed warnings from gcc, and clean up memory when closing archives --- paxinc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'paxinc.c') diff --git a/paxinc.c b/paxinc.c index 11768d2..ea41dfb 100644 --- a/paxinc.c +++ b/paxinc.c @@ -1,7 +1,7 @@ /* * Copyright 2003-2012 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 - * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxinc.c,v 1.15 2012/11/04 07:26:24 vapier Exp $ + * $Header: /var/cvsroot/gentoo-projects/pax-utils/paxinc.c,v 1.16 2013/04/10 22:16:45 vapier Exp $ * * Copyright 2005-2012 Ned Ludd - * Copyright 2005-2012 Mike Frysinger - @@ -53,12 +53,15 @@ archive_handle *ar_open(const char *filename) archive_member *ar_next(archive_handle *ar) { char *s; - size_t len = 0; + ssize_t len = 0; static archive_member ret; if (ar->skip && lseek(ar->fd, ar->skip, SEEK_CUR) == -1) { close_and_ret: + free(ar->extfn); close(ar->fd); + ar->extfn = NULL; + ar->fd = -1; return NULL; } @@ -84,7 +87,6 @@ close_and_ret: goto close_and_ret; } len = atoi(ret.buf.formatted.size); - /* we will leak this memory */ ar->extfn = xmalloc(sizeof(char) * (len + 1)); if (read(ar->fd, ar->extfn, len) != len) goto close_and_ret; @@ -100,7 +102,7 @@ close_and_ret: if (s[0] == '#' && s[1] == '1' && s[2] == '/') { /* BSD extended filename, always in use on Darwin */ len = atoi(s + 3); - if (len <= sizeof(ret.buf.formatted.name)) { + if (len <= (ssize_t)sizeof(ret.buf.formatted.name)) { if (read(ar->fd, ret.buf.formatted.name, len) != len) goto close_and_ret; } else { -- cgit v1.2.3-65-gdbad