Blame SOURCES/hdparm-9.54-resourceleak-fixes.patch

Justin Vreeland b079dd
diff -urN hdparm-9.54/fibmap.c hdparm-9.54_patched/fibmap.c
Justin Vreeland b079dd
--- hdparm-9.54/fibmap.c	2016-10-13 01:50:52.000000000 +0200
Justin Vreeland b079dd
+++ hdparm-9.54_patched/fibmap.c	2018-10-04 12:17:39.630627349 +0200
Justin Vreeland b079dd
@@ -232,6 +232,7 @@
Justin Vreeland b079dd
 	if (fstat(fd, &st) == -1) {
Justin Vreeland b079dd
 		err = errno;
Justin Vreeland b079dd
 		perror(file_name);
Justin Vreeland b079dd
+		close(fd);
Justin Vreeland b079dd
 		return err;
Justin Vreeland b079dd
 	}
Justin Vreeland b079dd
 	if (!S_ISREG(st.st_mode)) {
Justin Vreeland b079dd
diff -urN hdparm-9.54/fwdownload.c hdparm-9.54_patched/fwdownload.c
Justin Vreeland b079dd
--- hdparm-9.54/fwdownload.c	2017-12-06 13:41:40.000000000 +0100
Justin Vreeland b079dd
+++ hdparm-9.54_patched/fwdownload.c	2018-10-04 12:19:23.819336125 +0200
Justin Vreeland b079dd
@@ -95,12 +95,19 @@
Justin Vreeland b079dd
 	int xfer_min = 1, xfer_max = 0xffff, xfer_size;
Justin Vreeland b079dd
 	ssize_t offset;
Justin Vreeland b079dd
 
Justin Vreeland b079dd
-	if ((fwfd = open(fwpath, O_RDONLY)) == -1 || fstat(fwfd, &st) == -1) {
Justin Vreeland b079dd
+	if ((fwfd = open(fwpath, O_RDONLY)) == -1) {
Justin Vreeland b079dd
 		err = errno;
Justin Vreeland b079dd
 		perror(fwpath);
Justin Vreeland b079dd
 		return err;
Justin Vreeland b079dd
 	}
Justin Vreeland b079dd
 
Justin Vreeland b079dd
+	if (fstat(fwfd, &st) == -1) {
Justin Vreeland b079dd
+		err = errno;
Justin Vreeland b079dd
+		perror(fwpath);
Justin Vreeland b079dd
+		close(fwfd);
Justin Vreeland b079dd
+		return err;
Justin Vreeland b079dd
+	}
Justin Vreeland b079dd
+
Justin Vreeland b079dd
 	if (!S_ISREG(st.st_mode)) {
Justin Vreeland b079dd
 		fprintf(stderr, "%s: not a regular file\n", fwpath);
Justin Vreeland b079dd
 		err = EINVAL;
Justin Vreeland b079dd
diff -urN hdparm-9.54/hdparm.c hdparm-9.54_patched/hdparm.c
Justin Vreeland b079dd
--- hdparm-9.54/hdparm.c	2018-02-03 19:10:40.000000000 +0100
Justin Vreeland b079dd
+++ hdparm-9.54_patched/hdparm.c	2018-10-04 13:25:58.924126976 +0200
Justin Vreeland b079dd
@@ -590,6 +590,9 @@
Justin Vreeland b079dd
 	printf("\n");
Justin Vreeland b079dd
 	printf("\n * signifies the current active mode\n");
Justin Vreeland b079dd
 	printf("\n");
Justin Vreeland b079dd
+	free(fwrev);
Justin Vreeland b079dd
+	free(model);
Justin Vreeland b079dd
+	free(serno);
Justin Vreeland b079dd
 }
Justin Vreeland b079dd
 
Justin Vreeland b079dd
 static const char *busstate_str (unsigned int value)
Justin Vreeland b079dd
@@ -1174,8 +1177,10 @@
Justin Vreeland b079dd
 	if (!shortened)
Justin Vreeland b079dd
 		fdevname = strdup("the full disk");
Justin Vreeland b079dd
 
Justin Vreeland b079dd
-	if (start_lba == 0ULL)
Justin Vreeland b079dd
+	if (start_lba == 0ULL) {
Justin Vreeland b079dd
+		free(fdevname);
Justin Vreeland b079dd
 		return 0;
Justin Vreeland b079dd
+	}
Justin Vreeland b079dd
 	if (start_lba == START_LBA_UNKNOWN || fd_is_raid(fd)) {
Justin Vreeland b079dd
 		fprintf(stderr, "%s is a RAID device: please specify an absolute LBA of a raw member device instead (raid1 only)\n", devname);
Justin Vreeland b079dd
 	} else if (msg) {
Justin Vreeland b079dd
@@ -1187,6 +1192,7 @@
Justin Vreeland b079dd
 		fprintf(stderr, "The absolute LBA of sector %llu from %s should be %llu\n", lba, devname, start_lba + lba);
Justin Vreeland b079dd
 	}
Justin Vreeland b079dd
 	fprintf(stderr, "Aborting.\n");
Justin Vreeland b079dd
+	free(fdevname);
Justin Vreeland b079dd
 	exit(EINVAL);
Justin Vreeland b079dd
 }
Justin Vreeland b079dd
 
Justin Vreeland b079dd
diff -urN hdparm-9.54/sysfs.c hdparm-9.54_patched/sysfs.c
Justin Vreeland b079dd
--- hdparm-9.54/sysfs.c	2018-10-04 12:14:29.900157666 +0200
Justin Vreeland b079dd
+++ hdparm-9.54_patched/sysfs.c	2018-10-04 14:13:07.056659514 +0200
Justin Vreeland b079dd
@@ -60,8 +63,8 @@
Justin Vreeland b079dd
 		}
Justin Vreeland b079dd
 		if (count < 0)
Justin Vreeland b079dd
 			err = errno;
Justin Vreeland b079dd
-		fclose(fp);
Justin Vreeland b079dd
 	}
Justin Vreeland b079dd
+	fclose(fp);
Justin Vreeland b079dd
 	if (err && verbose) perror(path);
Justin Vreeland b079dd
 	*pathtail = '\0';
Justin Vreeland b079dd
 	return err;