Skip to content

Commit

Permalink
Merge branch 'rs/unpack-trees-leakfix'
Browse files Browse the repository at this point in the history
By René Scharfe
* rs/unpack-trees-leakfix:
  unpack-trees: plug minor memory leak
  unpack-trees: don't perform any index operation if we're not merging
  • Loading branch information
gitster committed Apr 16, 2012
2 parents 0e9b0ac + 6ff264e commit 27ed435
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions unpack-trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,28 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
opts->unpack_rejects[i].strdup_strings = 1;
}

static void add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
unsigned int set, unsigned int clear)
static void do_add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
unsigned int set, unsigned int clear)
{
unsigned int size = ce_size(ce);
struct cache_entry *new = xmalloc(size);

clear |= CE_HASHED | CE_UNHASHED;

if (set & CE_REMOVE)
set |= CE_WT_REMOVE;

ce->next = NULL;
ce->ce_flags = (ce->ce_flags & ~clear) | set;
add_index_entry(&o->result, ce,
ADD_CACHE_OK_TO_ADD | ADD_CACHE_OK_TO_REPLACE);
}

static void add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
unsigned int set, unsigned int clear)
{
unsigned int size = ce_size(ce);
struct cache_entry *new = xmalloc(size);

memcpy(new, ce, size);
new->next = NULL;
new->ce_flags = (new->ce_flags & ~clear) | set;
add_index_entry(&o->result, new, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
do_add_entry(o, new, set, clear);
}

/*
Expand Down Expand Up @@ -587,7 +594,7 @@ static int unpack_nondirectories(int n, unsigned long mask,

for (i = 0; i < n; i++)
if (src[i] && src[i] != o->df_conflict_entry)
add_entry(o, src[i], 0, 0);
do_add_entry(o, src[i], 0, 0);
return 0;
}

Expand Down Expand Up @@ -772,7 +779,7 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
if (unpack_nondirectories(n, mask, dirmask, src, names, info) < 0)
return -1;

if (src[0]) {
if (o->merge && src[0]) {
if (ce_stage(src[0]))
mark_ce_used_same_name(src[0], o);
else
Expand Down

0 comments on commit 27ed435

Please sign in to comment.