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

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