"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: don't leak memory in the object cache
To:
Omar Polo <op@omarpolo.com>
Cc:
gameoftrees@openbsd.org
Date:
Mon, 5 Sep 2022 11:23:22 +0200

Download raw body.

Thread
On Sun, Sep 04, 2022 at 07:59:02PM +0200, Omar Polo wrote:
> We fail to release the memory in the object cache when closing a
> repository.  (This was actually been reported by valgrind.)
> 
> After this my hacked loop in `got blame' leaks less!  (read: there is
> more to come as I'm grokking valgrind output.)
> 
> ok?

Nice find, ok stsp@

> diff /home/op/w/got
> commit - 04666d1a54c25c8be7e39bc628b4a80f3376c127
> path + /home/op/w/got
> blob - 5eabe168cdf8761b740fde3af077823aa688346e
> file + lib/object_cache.c
> --- lib/object_cache.c
> +++ lib/object_cache.c
> @@ -360,6 +360,35 @@ check_refcount(struct got_object_id *id, void *data, v
>  }
>  #endif
>  
> +static const struct got_error *
> +free_entry(struct got_object_id *id, void *data, void *arg)
> +{
> +	struct got_object_cache *cache = arg;
> +	struct got_object_cache_entry *ce = data;
> +
> +	switch (cache->type) {
> +	case GOT_OBJECT_CACHE_TYPE_OBJ:
> +		got_object_close(ce->data.obj);
> +		break;
> +	case GOT_OBJECT_CACHE_TYPE_TREE:
> +		got_object_tree_close(ce->data.tree);
> +		break;
> +	case GOT_OBJECT_CACHE_TYPE_COMMIT:
> +		got_object_commit_close(ce->data.commit);
> +		break;
> +	case GOT_OBJECT_CACHE_TYPE_TAG:
> +		got_object_tag_close(ce->data.tag);
> +		break;
> +	case GOT_OBJECT_CACHE_TYPE_RAW:
> +		got_object_raw_close(ce->data.raw);
> +		break;
> +	}
> +
> +	free(ce);
> +
> +	return NULL;
> +}
> +
>  void
>  got_object_cache_close(struct got_object_cache *cache)
>  {
> @@ -387,6 +416,7 @@ got_object_cache_close(struct got_object_cache *cache)
>  #endif
>  
>  	if (cache->idset) {
> +		got_object_idset_for_each(cache->idset, free_entry, cache);
>  		got_object_idset_free(cache->idset);
>  		cache->idset = NULL;
>  	}
> 
>