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

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