[Ocfs2-tools-devel] [PATCH 2/8] Fix a memory leak problem in freefs.c
piaojun
piaojun at huawei.com
Sun Mar 29 01:19:52 PDT 2015
Hi Mark,
The whitespace errors are all fixed and there are no obvious style
problems in the patch now. Thanks for reviewing!
Signed-off-by: Jun Piao <piaojun at huawei.com>
Reviewed-by: Alex Chen <alex.chen at huawei.com>
---
libocfs2/freefs.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/libocfs2/freefs.c b/libocfs2/freefs.c
index ab8a8ea..e67d7ee 100644
--- a/libocfs2/freefs.c
+++ b/libocfs2/freefs.c
@@ -32,18 +32,47 @@
#include "ocfs2/ocfs2.h"
+void ocfs2_free_fs_inode_allocs(ocfs2_filesys *fs)
+{
+ uint16_t i;
+ uint16_t max_slots = 0;
+ struct ocfs2_super_block *osb = OCFS2_RAW_SB(fs->fs_super);
+
+ if (!osb)
+ return;
+ max_slots = osb->s_max_slots;
+ ocfs2_free_cached_inode(fs, fs->fs_system_inode_alloc);
+
+ if (fs->fs_inode_allocs) {
+ for (i = 0; i < max_slots; i++)
+ ocfs2_free_cached_inode(fs, fs->fs_inode_allocs[i]);
+ }
+
+ if (fs->fs_eb_allocs) {
+ for (i = 0; i < max_slots; i++)
+ ocfs2_free_cached_inode(fs, fs->fs_eb_allocs[i]);
+ }
+}
void ocfs2_freefs(ocfs2_filesys *fs)
{
if (!fs)
abort();
+ ocfs2_free_fs_inode_allocs(fs);
+
if (fs->fs_orig_super)
ocfs2_free(&fs->fs_orig_super);
if (fs->fs_super)
ocfs2_free(&fs->fs_super);
if (fs->fs_devname)
ocfs2_free(&fs->fs_devname);
+ if (fs->fs_inode_allocs)
+ ocfs2_free(&fs->fs_inode_allocs);
+ if (fs->fs_eb_allocs)
+ ocfs2_free(&fs->fs_eb_allocs);
+ if (fs->ost)
+ ocfs2_free(&fs->ost);
if (fs->fs_io)
io_close(fs->fs_io);
--
1.8.4.3
在 2015/3/18 15:38, piaojun 写道:
> In ocfs2_freefs(), fs->fs_inode_allocs and fs->fs_eb_allocs are two level
> pointer, so every element in array should be freed through
> ocfs2_free_fs_inode_allocs(). Besides fs->fs_inode_allocs, fs->fs_eb_allocs
> and fs->ost should be freed after use.
>
> Signed-off-by: Jun Piao <piaojun at huawei.com>
> Reviewed-by: Alex Chen <alex.chen at huawei.com>
>
> ---
> libocfs2/freefs.c | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/libocfs2/freefs.c b/libocfs2/freefs.c
> index ab8a8ea..1fa9424 100644
> --- a/libocfs2/freefs.c
> +++ b/libocfs2/freefs.c
> @@ -32,18 +32,50 @@
>
> #include "ocfs2/ocfs2.h"
>
> +void ocfs2_free_fs_inode_allocs(ocfs2_filesys *fs)
> +{
> + uint16_t i;
> + uint16_t max_slots = 0;
> + struct ocfs2_super_block *osb = OCFS2_RAW_SB(fs->fs_super);
> + if (!osb)
> + return;
> + max_slots = osb->s_max_slots;
> + ocfs2_free_cached_inode(fs, fs->fs_system_inode_alloc);
> +
> + if (fs->fs_inode_allocs) {
> + for (i = 0; i < max_slots; i++) {
> + ocfs2_free_cached_inode(fs, fs->fs_inode_allocs[i]);
> + }
> + }
> +
> + if (fs->fs_eb_allocs) {
> + for (i = 0; i < max_slots; i++) {
> + ocfs2_free_cached_inode(fs, fs->fs_eb_allocs[i]);
> + }
> + }
> +
> + return;
> +}
>
> void ocfs2_freefs(ocfs2_filesys *fs)
> {
> if (!fs)
> abort();
>
> + ocfs2_free_fs_inode_allocs(fs);
> +
> if (fs->fs_orig_super)
> ocfs2_free(&fs->fs_orig_super);
> if (fs->fs_super)
> ocfs2_free(&fs->fs_super);
> if (fs->fs_devname)
> ocfs2_free(&fs->fs_devname);
> + if (fs->fs_inode_allocs)
> + ocfs2_free(&fs->fs_inode_allocs);
> + if (fs->fs_eb_allocs)
> + ocfs2_free(&fs->fs_eb_allocs);
> + if (fs->ost)
> + ocfs2_free(&fs->ost);
> if (fs->fs_io)
> io_close(fs->fs_io);
>
> -- 1.8.4.3
>
>
> _______________________________________________
> Ocfs2-tools-devel mailing list
> Ocfs2-tools-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/ocfs2-tools-devel
>
>
More information about the Ocfs2-tools-devel
mailing list