Browse Source

Merge branch 'jn/maint-plug-leak' into maint

* jn/maint-plug-leak:
  write-tree: Avoid leak when index refers to an invalid object
  read-tree: stop leaking tree objects
  core: Stop leaking ondisk_cache_entrys
maint
Junio C Hamano 15 years ago
parent
commit
16bfbe6352
  1. 4
      cache-tree.c
  2. 5
      read-cache.c
  3. 7
      unpack-trees.c

4
cache-tree.c

@ -328,9 +328,11 @@ static int update_one(struct cache_tree *it,
mode = ce->ce_mode; mode = ce->ce_mode;
entlen = pathlen - baselen; entlen = pathlen - baselen;
} }
if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1)) if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1)) {
strbuf_release(&buffer);
return error("invalid object %06o %s for '%.*s'", return error("invalid object %06o %s for '%.*s'",
mode, sha1_to_hex(sha1), entlen+baselen, path); mode, sha1_to_hex(sha1), entlen+baselen, path);
}


if (ce->ce_flags & CE_REMOVE) if (ce->ce_flags & CE_REMOVE)
continue; /* entry being removed */ continue; /* entry being removed */

5
read-cache.c

@ -1516,6 +1516,7 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
int size = ondisk_ce_size(ce); int size = ondisk_ce_size(ce);
struct ondisk_cache_entry *ondisk = xcalloc(1, size); struct ondisk_cache_entry *ondisk = xcalloc(1, size);
char *name; char *name;
int result;


ondisk->ctime.sec = htonl(ce->ce_ctime.sec); ondisk->ctime.sec = htonl(ce->ce_ctime.sec);
ondisk->mtime.sec = htonl(ce->ce_mtime.sec); ondisk->mtime.sec = htonl(ce->ce_mtime.sec);
@ -1539,7 +1540,9 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce)
name = ondisk->name; name = ondisk->name;
memcpy(name, ce->name, ce_namelen(ce)); memcpy(name, ce->name, ce_namelen(ce));


return ce_write(c, fd, ondisk, size); result = ce_write(c, fd, ondisk, size);
free(ondisk);
return result;
} }


int write_index(struct index_state *istate, int newfd) int write_index(struct index_state *istate, int newfd)

7
unpack-trees.c

@ -329,6 +329,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long
{ {
int i, ret, bottom; int i, ret, bottom;
struct tree_desc t[MAX_UNPACK_TREES]; struct tree_desc t[MAX_UNPACK_TREES];
void *buf[MAX_UNPACK_TREES];
struct traverse_info newinfo; struct traverse_info newinfo;
struct name_entry *p; struct name_entry *p;


@ -346,12 +347,16 @@ static int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long
const unsigned char *sha1 = NULL; const unsigned char *sha1 = NULL;
if (dirmask & 1) if (dirmask & 1)
sha1 = names[i].sha1; sha1 = names[i].sha1;
fill_tree_descriptor(t+i, sha1); buf[i] = fill_tree_descriptor(t+i, sha1);
} }


bottom = switch_cache_bottom(&newinfo); bottom = switch_cache_bottom(&newinfo);
ret = traverse_trees(n, t, &newinfo); ret = traverse_trees(n, t, &newinfo);
restore_cache_bottom(&newinfo, bottom); restore_cache_bottom(&newinfo, bottom);

for (i = 0; i < n; i++)
free(buf[i]);

return ret; return ret;
} }



Loading…
Cancel
Save