diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2013-12-06 00:04:39 +0100 |
---|---|---|
committer | Justus Winter <4winter@informatik.uni-hamburg.de> | 2013-12-09 15:08:00 +0100 |
commit | 2640c8a8e32c2f20023e4cb91f87684c62316f19 (patch) | |
tree | 7944ce0ce0ff03ab6e5394316ea573c679886615 /trans/fakeroot.c | |
parent | 7d20408ec4a5dbc973520dd78dd2531c6a1471c7 (diff) |
trans: improve the error handling in fakeauth
Previously the node was not correctly torn down if adding the newly
created netnode to the hash table failed. Fix this by rearranging the
code, doing the hash table modification first because it is easier to
undo.
* trans/fakeroot.c (new_node): Fix the error handling.
Diffstat (limited to 'trans/fakeroot.c')
-rw-r--r-- | trans/fakeroot.c | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/trans/fakeroot.c b/trans/fakeroot.c index 5c4854d1..3756f489 100644 --- a/trans/fakeroot.c +++ b/trans/fakeroot.c @@ -95,28 +95,31 @@ new_node (file_t file, mach_port_t idport, int locked, int openmodes, return err; } } + + if (!locked) + pthread_mutex_lock (&idport_ihash_lock); + err = hurd_ihash_add (&idport_ihash, nn->idport, nn); + if (err) + goto lose; + *np = nn->np = netfs_make_node (nn); if (*np == 0) { - if (locked) - pthread_mutex_unlock (&idport_ihash_lock); err = ENOMEM; + goto lose_hash; } - else - { - if (!locked) - pthread_mutex_lock (&idport_ihash_lock); - err = hurd_ihash_add (&idport_ihash, nn->idport, nn); - if (!err) - pthread_mutex_lock (&(*np)->lock); - pthread_mutex_unlock (&idport_ihash_lock); - } - if (err) - { - mach_port_deallocate (mach_task_self (), nn->idport); - mach_port_deallocate (mach_task_self (), file); - free (nn); - } + + pthread_mutex_lock (&(*np)->lock); + pthread_mutex_unlock (&idport_ihash_lock); + return 0; + + lose_hash: + hurd_ihash_locp_remove (&idport_ihash, nn->idport_locp); + lose: + pthread_mutex_unlock (&idport_ihash_lock); + mach_port_deallocate (mach_task_self (), nn->idport); + mach_port_deallocate (mach_task_self (), file); + free (nn); return err; } |