diff options
author | Lancelot SIX <lancelot@lancleotsix.com> | 2014-12-25 22:01:53 +0100 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2014-12-26 11:46:11 +0100 |
commit | 5fe615a4d66f4dea48812ed9e4f250010a8f9298 (patch) | |
tree | 0a8bf99ad56974f634f42605340d0e1bb63fd6d0 /procfs | |
parent | 8e3c26e98bcf30dd73a8c64bb9aab08e2f32c1f8 (diff) |
Make sure to free content dir in procfs
In procfs/netfs.c:netfs_get_dirents, make sure to free the memory
allocated with the "get_contents" callback of nodes.
Diffstat (limited to 'procfs')
-rw-r--r-- | procfs/netfs.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/procfs/netfs.c b/procfs/netfs.c index 276c57cc..737abbc9 100644 --- a/procfs/netfs.c +++ b/procfs/netfs.c @@ -161,6 +161,8 @@ error_t netfs_get_dirents (struct iouser *cred, struct node *dir, vm_size_t bufsize, int *amt) { char *contents; + char *first_content; // Keep pointer to the dir content's buffer to free it + // at the end of the procedure ssize_t contents_len; error_t err; @@ -170,6 +172,7 @@ error_t netfs_get_dirents (struct iouser *cred, struct node *dir, err = procfs_get_contents (dir, &contents, &contents_len); if (err) return err; + first_content = contents; /* We depend on the fact that CONTENTS is terminated. */ assert (contents_len == 0 || contents[contents_len - 1] == '\0'); @@ -188,7 +191,10 @@ error_t netfs_get_dirents (struct iouser *cred, struct node *dir, { char *n = mmap (0, *datacnt, PROT_READ | PROT_WRITE, MAP_ANONYMOUS, 0, 0); if (n == MAP_FAILED) - return ENOMEM; + { + free (first_content); + return ENOMEM; + } *data = n; } @@ -196,6 +202,7 @@ error_t netfs_get_dirents (struct iouser *cred, struct node *dir, /* Do the actual conversion. */ *amt = putentries (contents, contents_len, nentries, *data, datacnt); + free (first_content); return 0; } |