From 29e3c6c5c3936b75f16811071e77904900edd86e Mon Sep 17 00:00:00 2001 From: Toshiaki Takahashi Date: Wed, 6 Dec 2017 12:19:41 +0000 Subject: [PATCH] df: fix memory leak in error case Because the memory of the STATANYFS list is not released when the read callback function error occurs, a memory leak may occur. With this change, the memory is always released by not returning in the loop. Signed-off-by: Florian Forster --- src/df.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/df.c b/src/df.c index dd90f243..688c3222 100644 --- a/src/df.c +++ b/src/df.c @@ -152,6 +152,7 @@ static int df_read(void) { #elif HAVE_STATFS struct statfs statbuf; #endif + int retval = 0; /* struct STATANYFS statbuf; */ cu_mount_t *mnt_list; @@ -284,8 +285,10 @@ static int df_read(void) { (gauge_t)((float_t)(blk_reserved) / statbuf.f_blocks * 100)); df_submit_one(disk_name, "percent_bytes", "used", (gauge_t)((float_t)(blk_used) / statbuf.f_blocks * 100)); - } else - return -1; + } else { + retval = -1; + break; + } } /* inode handling */ @@ -315,8 +318,10 @@ static int df_read(void) { df_submit_one( disk_name, "percent_inodes", "used", (gauge_t)((float_t)(inode_used) / statbuf.f_files * 100)); - } else - return -1; + } else { + retval = -1; + break; + } } if (values_absolute) { df_submit_one(disk_name, "df_inodes", "free", (gauge_t)inode_free); @@ -329,7 +334,7 @@ static int df_read(void) { cu_mount_freelist(mnt_list); - return 0; + return retval; } /* int df_read */ void module_register(void) { -- 2.11.0