From ccd8169ce142928e1b8d3e579e5de631dd98575e Mon Sep 17 00:00:00 2001 From: Stian Skjelstad Date: Mon, 15 Apr 2024 13:06:07 +0200 Subject: [PATCH] If calloc() failed, ref() count would be out of balance. --- filesel/filesystem-filehandle-cache.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/filesel/filesystem-filehandle-cache.c b/filesel/filesystem-filehandle-cache.c index 7585b6d3..d6147a4c 100644 --- a/filesel/filesystem-filehandle-cache.c +++ b/filesel/filesystem-filehandle-cache.c @@ -111,8 +111,6 @@ struct ocpfilehandle_t *cache_filehandle_open (struct ocpfilehandle_t *parent) 1 /* refcount */ ); - parent->origin->ref (parent->origin); - s->cache_line[0].data = calloc (1, CACHE_LINE_SIZE); if (!s->cache_line[0].data) { @@ -122,7 +120,8 @@ struct ocpfilehandle_t *cache_filehandle_open (struct ocpfilehandle_t *parent) } s->parent = parent; - s->parent->ref (s->parent); + parent->ref (s->parent); + parent->origin->ref (parent->origin); /* prefill cache-line 0 which is dedicated for the start of the file */