File Fix-Double-free-issue-found-with-Clang-Static-Analyz.patch of Package partclone.openSUSE_Leap_42.3_Update

From dea1d162bdd2139000972a204715826c835708b9 Mon Sep 17 00:00:00 2001
From: Leslie Zhai <xiangzhai83@gmail.com>
Date: Fri, 23 Dec 2016 15:15:17 +0800
Subject: [PATCH] Fix Double free issue found with Clang Static Analyzer #2

Patch-mainline: 0.3.10
Git-commit: dea1d162bdd2139000972a204715826c835708b9

Reviewers: @yetist
Acked-by: Michal Suchanek <msuchanek@suse.de>
---
 src/partclone.c | 12 ++++++------
 src/version.h   |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/partclone.c b/src/partclone.c
index 68d27f3ee94e..da6d4ad8e61d 100644
--- a/src/partclone.c
+++ b/src/partclone.c
@@ -1371,7 +1371,7 @@ int check_mount(const char* device, char* mount_p){
 int open_source(char* source, cmd_opt* opt) {
 	int ret = 0;
 	int debug = opt->debug;
-	char *mp;
+	char *mp = NULL;
 	int flags = O_RDONLY | O_LARGEFILE;
         struct stat st_dev;
 	int ddd_block_device = -1;
@@ -1397,10 +1397,10 @@ int open_source(char* source, cmd_opt* opt) {
 
 		if (check_mount(source, mp) == 1) {
 			log_mesg(0, 0, 1, debug, "device (%s) is mounted at %s\n", source, mp);
-			free(mp);
+			free(mp); mp = NULL;
 			log_mesg(0, 1, 1, debug, "error exit\n");
 		}
-		free(mp);
+		if (mp) free(mp); mp = NULL;
 
 		if ((ret = open(source, flags, S_IRUSR)) == -1)
 			log_mesg(0, 1, 1, debug, "clone: open %s error\n", source);
@@ -1422,7 +1422,7 @@ int open_source(char* source, cmd_opt* opt) {
 int open_target(char* target, cmd_opt* opt) {
 	int ret = 0;
 	int debug = opt->debug;
-	char *mp;
+	char *mp = NULL;
 	int flags = O_WRONLY | O_LARGEFILE;
 	struct stat st_dev;
 	int ddd_block_device = -1;
@@ -1469,10 +1469,10 @@ int open_target(char* target, cmd_opt* opt) {
 			log_mesg(0, 1, 1, debug, "%s, %i, not enough memory\n", __func__, __LINE__);
 		if (check_mount(target, mp)) {
 			log_mesg(0, 0, 1, debug, "device (%s) is mounted at %s\n", target, mp);
-			free(mp);
+			free(mp); mp = NULL;
 			log_mesg(0, 1, 1, debug, "error exit\n");
 		}
-		free(mp);
+		if (mp) free(mp); mp = NULL;
 
 		/// check block device
 		stat(target, &st_dev);
openSUSE Build Service is sponsored by