From owner-p4-projects@FreeBSD.ORG Thu Jul 17 21:00:35 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id DA728106567F; Thu, 17 Jul 2008 21:00:34 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9E7DF106567D for ; Thu, 17 Jul 2008 21:00:34 +0000 (UTC) (envelope-from strauss@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 67A818FC20 for ; Thu, 17 Jul 2008 21:00:34 +0000 (UTC) (envelope-from strauss@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m6HL0Xa6033337 for ; Thu, 17 Jul 2008 21:00:33 GMT (envelope-from strauss@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m6HL0Xqi033335 for perforce@freebsd.org; Thu, 17 Jul 2008 21:00:33 GMT (envelope-from strauss@FreeBSD.org) Date: Thu, 17 Jul 2008 21:00:33 GMT Message-Id: <200807172100.m6HL0Xqi033335@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to strauss@FreeBSD.org using -f From: Anselm Strauss To: Perforce Change Reviews Cc: Subject: PERFORCE change 145391 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jul 2008 21:00:35 -0000 http://perforce.freebsd.org/chv.cgi?CH=145391 Change 145391 by strauss@strauss_marvelman on 2008/07/17 20:59:42 Never mix up static and automatic storage duration Affected files ... .. //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#11 edit Differences ... ==== //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#11 (text+ko) ==== @@ -97,15 +97,20 @@ archive_write_set_format_zip(struct archive *_a) { struct archive_write *a = (struct archive_write *)_a; - struct zip zip; + struct zip *zip; /* If another format was already registered, unregister it. */ if (a->format_destroy != NULL) (a->format_destroy)(a); + + zip = (struct zip *) malloc(sizeof(*zip)); + if (zip == NULL) { + archive_set_error(&a->archive, ENOMEM, "Can't allocate zip data"); + return (ARCHIVE_FATAL); + } + zip->central_directory = NULL; + a->format_data = zip; - zip->central_directory = NULL; /* To be sure. */ - a->format_data = &zip; - a->pad_uncompressed = 0; /* Actually not needed for now, since no compression support yet. */ a->format_write_header = archive_write_zip_header; a->format_write_data = archive_write_zip_data; @@ -117,8 +122,8 @@ encode( ZIP_SIGNATURE_DATA_DESCRIPTOR, - &zip.data_descriptor.signature, - sizeof(zip.data_descriptor.signature) + &zip->data_descriptor.signature, + sizeof(zip->data_descriptor.signature) ); return (ARCHIVE_OK); @@ -134,7 +139,7 @@ struct zip *zip; struct zip_local_file_header h; struct zip_data_descriptor *d; - struct zip_entry_list l; + struct zip_entry_list *l; int ret; zip = (struct zip *) a->format_data; @@ -168,9 +173,14 @@ /* Append archive entry to the central directory data. * Storing in reverse order, for ease of coding. * According to specification order should not matter, right? */ - l.entry = entry; - l.next = zip->central_directory; - zip->central_directory = &l; + l = (struct zip_entry_list *) malloc(sizeof(*l)); + if (l == NULL) { + archive_set_error(&a->archive, ENOMEM, "Can't allocate zip header data"); + return (ARCHIVE_FATAL); + } + l->entry = entry; + l->next = zip->central_directory; + zip->central_directory = l; int64_t size = archive_entry_size(entry); encode(size, &d->compressed_size, sizeof(d->compressed_size)); @@ -229,8 +239,14 @@ archive_write_zip_destroy(struct archive_write *a) { struct zip *zip; + struct zip_entry_list *l; zip = (struct zip *)a->format_data; + l = (struct zip_entry_list *) zip->central_directory; + while (l != NULL) { + l = l->next; + free(l); + } free(zip); a->format_data = NULL; return (ARCHIVE_OK);