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

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