git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
To: Franck Bui-Huu <vagabon.xyz@gmail.com>
Cc: Junio C Hamano <junkio@cox.net>, git@vger.kernel.org
Subject: Re: [PATCH 1/2] Add git-archive
Date: Wed, 06 Sep 2006 22:17:53 +0200	[thread overview]
Message-ID: <44FF2CF1.9020201@lsrfire.ath.cx> (raw)
In-Reply-To: <cda58cb80609050516v699338b9y57fd54f50c66e49e@mail.gmail.com>

Franck Bui-Huu schrieb:
> diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c
> index 61a4135..e0da01e 100644
> --- a/builtin-tar-tree.c
> +++ b/builtin-tar-tree.c
> @@ -9,6 +9,7 @@ #include "strbuf.h"
> #include "tar.h"
> #include "builtin.h"
> #include "pkt-line.h"
> +#include "archive.h"
> 
> #define RECORDSIZE    (512)
> #define BLOCKSIZE    (RECORDSIZE * 20)
> @@ -338,6 +339,71 @@ static int generate_tar(int argc, const
>     return 0;
> }
> 
> +static int write_tar_entry(const unsigned char *sha1,
> +                           const char *base, int baselen,
> +                           const char *filename, unsigned mode, int stage)
> +{
> +    static struct strbuf path;
> +    int filenamelen = strlen(filename);
> +    void *buffer;
> +    char type[20];
> +    unsigned long size;
> +
> +    if (!path.alloc) {
> +        path.buf = xmalloc(PATH_MAX);
> +        path.alloc = PATH_MAX;
> +        path.len = path.eof = 0;
> +    }
> +    if (path.alloc < baselen + filenamelen) {
> +        free(path.buf);
> +        path.buf = xmalloc(baselen + filenamelen);
> +        path.alloc = baselen + filenamelen;
> +    }
> +    memcpy(path.buf, base, baselen);
> +    memcpy(path.buf + baselen, filename, filenamelen);
> +    path.len = baselen + filenamelen;
> +    if (S_ISDIR(mode)) {
> +        strbuf_append_string(&path, "/");
> +        buffer = NULL;
> +        size = 0;
> +    } else {
> +        buffer = read_sha1_file(sha1, type, &size);
> +        if (!buffer)
> +            die("cannot read %s", sha1_to_hex(sha1));
> +    }
> +
> +    write_entry(sha1, &path, mode, buffer, size);

Here occurs the memory leak that I've been talking about.  buffer needs
to be free'd.

> +
> +    return READ_TREE_RECURSIVE;
> +}

      parent reply	other threads:[~2006-09-06 20:18 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-05 12:16 [PATCH 1/2] Add git-archive Franck Bui-Huu
2006-09-05 19:23 ` Junio C Hamano
2006-09-06 13:46   ` Franck Bui-Huu
2006-09-06 20:14     ` Rene Scharfe
2006-09-06 20:29       ` Jakub Narebski
2006-09-08 20:21         ` Rene Scharfe
2006-09-06 21:42     ` Junio C Hamano
2006-09-07  6:32       ` Franck Bui-Huu
2006-09-07  7:19         ` Junio C Hamano
2006-09-07  7:53           ` Franck Bui-Huu
2006-09-07  8:16             ` Junio C Hamano
2006-09-07 13:08               ` Add git-archive [take #2] Franck Bui-Huu
2006-09-07 13:12                 ` [PATCH 1/4] Add git-archive Franck Bui-Huu
2006-09-08  2:35                   ` Junio C Hamano
2006-09-08  9:00                     ` Franck Bui-Huu
2006-09-08 20:21                       ` Rene Scharfe
2006-09-09 14:31                         ` Franck Bui-Huu
2006-09-09 15:02                           ` Rene Scharfe
2006-09-09 15:25                             ` Franck Bui-Huu
2006-09-07 13:12                 ` [PATCH 2/4] git-archive: wire up TAR format Franck Bui-Huu
2006-09-08 20:21                   ` Rene Scharfe
2006-09-08 21:42                     ` Junio C Hamano
2006-09-09  1:53                       ` Junio C Hamano
2006-09-09 15:02                         ` Rene Scharfe
2006-09-09 15:10                         ` Franck Bui-Huu
2006-09-09 19:42                           ` Junio C Hamano
2006-09-10 16:10                             ` [PATCH] Use xstrdup instead of strdup in builtin-{tar,zip}-tree.c Rene Scharfe
2006-09-09 14:38                     ` [PATCH 2/4] git-archive: wire up TAR format Franck Bui-Huu
2006-09-07 13:12                 ` [PATCH 3/4] git-archive: wire up ZIP format Franck Bui-Huu
2006-09-07 13:12                 ` [PATCH 4/4] Add git-upload-archive Franck Bui-Huu
2006-09-07 17:26                 ` Add git-archive [take #2] Franck Bui-Huu
2006-09-08  0:37                 ` Junio C Hamano
2006-09-08  8:18                   ` Franck Bui-Huu
2006-09-08  8:47                     ` Jakub Narebski
2006-09-08  8:58                     ` Junio C Hamano
2006-09-08  9:43                       ` Franck Bui-Huu
2006-09-08 21:42                         ` Junio C Hamano
2006-09-08 20:21                   ` Rene Scharfe
2006-09-08 21:42                     ` Junio C Hamano
2006-09-06 20:17 ` Rene Scharfe [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44FF2CF1.9020201@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire.ath.cx \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=vagabon.xyz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).