Re: [PATCH 1/2] Add git-archive
- From
Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
- Date
- Sep 6, 2006, 20:17 UTC
- Message-ID
- <44FF2CF1.9020201@lsrfire.ath.cx>
- In-Reply-To
- <cda58cb80609050516v699338b9y57fd54f50c66e49e@mail.gmail.com>
Franck Bui-Huu schrieb:
Show 50 quoted lines
> 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; > +}