diff options
author | Jeremie Koenig <jk@jk.fr.eu.org> | 2010-08-17 16:48:55 +0000 |
---|---|---|
committer | Jeremie Koenig <jk@jk.fr.eu.org> | 2010-08-30 14:14:48 +0200 |
commit | ac75e3648e6a9c3a8cf45d5fa491abd3a3ab3613 (patch) | |
tree | 42afd9455d4384b82a70625ec8b7194d4a08efda /procfs.c | |
parent | 3907bbbcfb806799a5349e46a2b804307a0e9836 (diff) |
Fix the failure semantics of procfs_make_node
* procfs.c (procfs_make_node): Invoke the cleanup callback on
failure, so that callers don't have to.
* procfs.h: Document the change.
* procfs_dir.c (procfs_dir_make_node), procfs_file.c
(procfs_file_make_node), proclist.c (proclist_make_node):
Update to reflect the change.
Diffstat (limited to 'procfs.c')
-rw-r--r-- | procfs.c | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -22,7 +22,7 @@ struct node *procfs_make_node (const struct procfs_node_ops *ops, void *hook) nn = malloc (sizeof *nn); if (! nn) - return NULL; + goto fail; memset (nn, 0, sizeof *nn); nn->ops = ops; @@ -30,10 +30,7 @@ struct node *procfs_make_node (const struct procfs_node_ops *ops, void *hook) np = netfs_make_node (nn); if (! np) - { - free (nn); - return NULL; - } + goto fail; np->nn = nn; memset (&np->nn_stat, 0, sizeof np->nn_stat); @@ -45,6 +42,13 @@ struct node *procfs_make_node (const struct procfs_node_ops *ops, void *hook) np->nn_stat.st_mode = S_IFREG | 0444; return np; + +fail: + if (ops->cleanup) + ops->cleanup (hook); + + free (nn); + return NULL; } error_t procfs_get_contents (struct node *np, void **data, size_t *data_len) |