From a9c74187eff3dcd7aa23a735e8ef07abf1546514 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 1 Jan 2023 11:32:32 +0100 Subject: make_peropen: Fix memory leaks on error --- libdiskfs/peropen-make.c | 11 +++++++++-- libnetfs/make-peropen.c | 8 ++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/libdiskfs/peropen-make.c b/libdiskfs/peropen-make.c index 827aa2d8..b4564a97 100644 --- a/libdiskfs/peropen-make.c +++ b/libdiskfs/peropen-make.c @@ -34,7 +34,10 @@ diskfs_make_peropen (struct node *np, int flags, struct peropen *context, err = fshelp_rlock_po_init (&po->lock_status); if (err) - return err; + { + free (po); + return err; + } po->filepointer = 0; refcount_init (&po->refcnt, 1); @@ -48,7 +51,11 @@ diskfs_make_peropen (struct node *np, int flags, struct peropen *context, { po->path = strdup (context->path); if (! po->path) - return ENOMEM; + { + fshelp_rlock_po_fini (&po->lock_status); + free (po); + return ENOMEM; + } } po->root_parent = context->root_parent; diff --git a/libnetfs/make-peropen.c b/libnetfs/make-peropen.c index 4bd74740..3b127881 100644 --- a/libnetfs/make-peropen.c +++ b/libnetfs/make-peropen.c @@ -34,7 +34,10 @@ netfs_make_peropen (struct node *np, int flags, struct peropen *context) po->filepointer = 0; err = fshelp_rlock_po_init (&po->lock_status); if (err) - return NULL; + { + free (po); + return NULL; + } refcount_init (&po->refcnt, 1); po->openstat = flags; po->np = np; @@ -46,7 +49,8 @@ netfs_make_peropen (struct node *np, int flags, struct peropen *context) { po->path = strdup (context->path); if (! po->path) { - free(po); + fshelp_rlock_po_fini (&po->lock_status); + free (po); return NULL; } } -- cgit v1.2.3