[PATCH 07/14] xfs_logprint: fix leak in error path of xlog_print_record()

Eric Sandeen sandeen at redhat.com
Tue Apr 8 18:24:57 CDT 2014


In 2 error paths we returned without freeing the allocated buf.
Collapse them into a compound test & free buf on the way out.

Signed-off-by: Eric Sandeen <sandeen at redhat.com>
---
 logprint/log_misc.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index 52f1e85..a022df4 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -942,11 +942,12 @@ xlog_print_record(
 	     */
 	    if (be32_to_cpu(rhead->h_cycle) !=
 			be32_to_cpu(*(__be32 *)ptr)) {
-		if (*read_type == FULL_READ)
-		    return -1;
-		else if (be32_to_cpu(rhead->h_cycle) + 1 !=
-			be32_to_cpu(*(__be32 *)ptr))
-		    return -1;
+		if ((*read_type == FULL_READ) ||
+		    (be32_to_cpu(rhead->h_cycle) + 1 !=
+				be32_to_cpu(*(__be32 *)ptr))) {
+			free(buf);
+			return -1;
+		}
 	    }
 	}
 
-- 
1.7.1



More information about the xfs mailing list