threads / patch / 48140

patchunpack-trees: release oid_array after use in check_updates()

Subject: [PATCH] unpack-trees: release oid_array after use in check_updates()

## tl;dr

2 messages between Mar 25, 2018 and Mar 25, 2018. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

René Scharfe· Mar 25, 2018, 16:31 UTC · lore
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
That leak was introduced by c0c578b33c (unpack-trees: batch fetching of
missing blobs).
 unpack-trees.c | 1 +
 1 file changed, 1 insertion(+)
Show changes to unpack-trees.c +1 −0
diff --git a/unpack-trees.c b/unpack-trees.c
index d5685891a5..e73745051e 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -379,30 +379,31 @@ static int check_updates(struct unpack_trees_options *o)
 		struct oid_array to_fetch = OID_ARRAY_INIT;
 		int fetch_if_missing_store = fetch_if_missing;
 		fetch_if_missing = 0;
 		for (i = 0; i < index->cache_nr; i++) {
 			struct cache_entry *ce = index->cache[i];
 			if ((ce->ce_flags & CE_UPDATE) &&
 			    !S_ISGITLINK(ce->ce_mode)) {
 				if (!has_object_file(&ce->oid))
 					oid_array_append(&to_fetch, &ce->oid);
 			}
 		}
 		if (to_fetch.nr)
 			fetch_objects(repository_format_partial_clone,
 				      &to_fetch);
 		fetch_if_missing = fetch_if_missing_store;
+		oid_array_clear(&to_fetch);
 	}
 	for (i = 0; i < index->cache_nr; i++) {
 		struct cache_entry *ce = index->cache[i];
 
 		if (ce->ce_flags & CE_UPDATE) {
 			if (ce->ce_flags & CE_WT_REMOVE)
 				die("BUG: both update and delete flags are set on %s",
 				    ce->name);
 			display_progress(progress, ++cnt);
 			ce->ce_flags &= ~CE_UPDATE;
 			if (o->update && !o->dry_run) {
 				errs |= checkout_entry(ce, &state, NULL);
 			}
 		}
 	}
-- 
2.16.3
Derrick Stolee· Mar 25, 2018, 18:33 UTC · re: René Scharfe · lore

Re: [PATCH] unpack-trees: release oid_array after use in check_updates()

On 3/25/2018 12:31 PM, René Scharfe wrote:
Show 44 quoted lines
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
> ---
> That leak was introduced by c0c578b33c (unpack-trees: batch fetching of
> missing blobs).
>
>   unpack-trees.c | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/unpack-trees.c b/unpack-trees.c
> index d5685891a5..e73745051e 100644
> --- a/unpack-trees.c
> +++ b/unpack-trees.c
> @@ -379,30 +379,31 @@ static int check_updates(struct unpack_trees_options *o)
>   		struct oid_array to_fetch = OID_ARRAY_INIT;
>   		int fetch_if_missing_store = fetch_if_missing;
>   		fetch_if_missing = 0;
>   		for (i = 0; i < index->cache_nr; i++) {
>   			struct cache_entry *ce = index->cache[i];
>   			if ((ce->ce_flags & CE_UPDATE) &&
>   			    !S_ISGITLINK(ce->ce_mode)) {
>   				if (!has_object_file(&ce->oid))
>   					oid_array_append(&to_fetch, &ce->oid);
>   			}
>   		}
>   		if (to_fetch.nr)
>   			fetch_objects(repository_format_partial_clone,
>   				      &to_fetch);
>   		fetch_if_missing = fetch_if_missing_store;
> +		oid_array_clear(&to_fetch);
>   	}
>   	for (i = 0; i < index->cache_nr; i++) {
>   		struct cache_entry *ce = index->cache[i];
>   
>   		if (ce->ce_flags & CE_UPDATE) {
>   			if (ce->ce_flags & CE_WT_REMOVE)
>   				die("BUG: both update and delete flags are set on %s",
>   				    ce->name);
>   			display_progress(progress, ++cnt);
>   			ce->ce_flags &= ~CE_UPDATE;
>   			if (o->update && !o->dry_run) {
>   				errs |= checkout_entry(ce, &state, NULL);
>   			}
>   		}
>   	}
Ack. Looks correct.
-Stolee

← back to recent threads