summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2013-09-21 12:54:25 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2013-09-21 12:54:25 +0200
commitec62f87ff6fb76b25a3455baa0c92e39aac6b259 (patch)
tree9fb4745aec7d291319dbc76a817f98f4f2fcfffe
parenta42e96e845840ff40c9c19b042743091cae0ca49 (diff)
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.
-rw-r--r--libdiskfs/peropen-make.c14
-rw-r--r--libnetfs/make-peropen.c21
2 files changed, 20 insertions, 15 deletions
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
{
diff --git a/libnetfs/make-peropen.c b/libnetfs/make-peropen.c
index 733bfdcb..7f2df053 100644
--- a/libnetfs/make-peropen.c
+++ b/libnetfs/make-peropen.c
@@ -25,7 +25,10 @@ struct peropen *
netfs_make_peropen (struct node *np, int flags, struct peropen *context)
{
struct peropen *po = malloc (sizeof (struct peropen));
-
+
+ if (!po)
+ return NULL;
+
po->filepointer = 0;
po->lock_status = LOCK_UN;
po->refcnt = 0;
@@ -35,6 +38,15 @@ netfs_make_peropen (struct node *np, int flags, struct peropen *context)
if (context)
{
+ if (context->path)
+ {
+ po->path = strdup (context->path);
+ if (! po->path) {
+ free(po);
+ return NULL;
+ }
+ }
+
po->root_parent = context->root_parent;
if (po->root_parent != MACH_PORT_NULL)
mach_port_mod_refs (mach_task_self (), po->root_parent,
@@ -48,13 +60,6 @@ netfs_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;
- }
}
netfs_nref (np);