summaryrefslogtreecommitdiff
path: root/procfs_dir.c
diff options
context:
space:
mode:
Diffstat (limited to 'procfs_dir.c')
-rw-r--r--procfs_dir.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/procfs_dir.c b/procfs_dir.c
index 62a45b1b..b7fb28fa 100644
--- a/procfs_dir.c
+++ b/procfs_dir.c
@@ -7,6 +7,7 @@ struct procfs_dir_node
{
const struct procfs_dir_entry *entries;
void *hook;
+ void (*cleanup) (void *hook);
};
static error_t
@@ -51,23 +52,41 @@ procfs_dir_lookup (void *hook, const char *name, struct node **np)
return 0;
}
+static void
+procfs_dir_cleanup (void *hook)
+{
+ struct procfs_dir_node *dn = hook;
+
+ if (dn->cleanup)
+ dn->cleanup (dn->hook);
+
+ free (dn);
+}
+
struct node *
-procfs_dir_make_node (const struct procfs_dir_entry *entries, void *dir_hook)
+procfs_dir_make_node (const struct procfs_dir_entry *entries,
+ void *dir_hook, void (*cleanup) (void *dir_hook))
{
static const struct procfs_node_ops ops = {
.get_contents = procfs_dir_get_contents,
.lookup = procfs_dir_lookup,
- .cleanup_contents = free,
- .cleanup = free,
+ .cleanup_contents = procfs_cleanup_contents_with_free,
+ .cleanup = procfs_dir_cleanup,
};
struct procfs_dir_node *dn;
dn = malloc (sizeof *dn);
if (! dn)
- return NULL;
+ {
+ if (cleanup)
+ cleanup (dir_hook);
+
+ return NULL;
+ }
dn->entries = entries;
dn->hook = dir_hook;
+ dn->cleanup = cleanup;
return procfs_make_node (&ops, dn);
}