From ec62f87ff6fb76b25a3455baa0c92e39aac6b259 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 21 Sep 2013 12:54:25 +0200 Subject: Fix ENOMEM handling in *_make_peropen * libdiskfs/peropen-make.c (diskfs_make_peropen): Move `strdup` before port reference modifications, to fix abortion. * libnetfs/make-peropen.c (netfs_make_peropen): Check for `malloc` failure. Move `strdup` before port reference modifications, to fix abortion. --- libdiskfs/peropen-make.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'libdiskfs/peropen-make.c') diff --git a/libdiskfs/peropen-make.c b/libdiskfs/peropen-make.c index b11b2ad6..eba037ff 100644 --- a/libdiskfs/peropen-make.c +++ b/libdiskfs/peropen-make.c @@ -38,6 +38,13 @@ diskfs_make_peropen (struct node *np, int flags, struct peropen *context, if (context) { + if (context->path) + { + po->path = strdup (context->path); + if (! po->path) + return ENOMEM; + } + po->root_parent = context->root_parent; if (po->root_parent != MACH_PORT_NULL) mach_port_mod_refs (mach_task_self (), po->root_parent, @@ -51,13 +58,6 @@ diskfs_make_peropen (struct node *np, int flags, struct peropen *context, if (po->shadow_root_parent != MACH_PORT_NULL) mach_port_mod_refs (mach_task_self (), po->shadow_root_parent, MACH_PORT_RIGHT_SEND, 1); - - if (context->path) - { - po->path = strdup (context->path); - if (! po->path) - return ENOMEM; - } } else { -- cgit v1.2.3