PATCH i-g-t small patch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

this is a small patch to fix couple of mem leaks, possible double free case.

Hope it is useful.

Kind regards.
From b2c1f0fa1aa8424b7d1200c2cc4171eeda719571 Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen@xxxxxxxxx>
Date: Thu, 5 May 2016 16:36:58 +0100
Subject: [PATCH i-g-t] couple of memory leak fixes. avoiding a double free.

---
 benchmarks/gem_mmap.c              |  1 +
 benchmarks/gem_syslatency.c        |  2 ++
 benchmarks/gem_userptr_benchmark.c |  4 +++-
 demos/intel_sprite_on.c            |  6 ++++++
 overlay/gpu-perf.c                 | 21 ++++++++++++++++++---
 tests/gem_render_linear_blits.c    |  7 ++++++-
 tests/gem_render_tiled_blits.c     |  2 ++
 tests/gem_tiled_swapping.c         |  1 +
 tests/kms_atomic.c                 |  1 +
 tests/kms_pipe_color.c             |  3 +++
 tests/prime_self_import.c          |  2 ++
 tools/intel_bios_dumper.c          |  1 +
 tools/intel_opregion_decode.c      |  7 +++++--
 13 files changed, 51 insertions(+), 7 deletions(-)

diff --git a/benchmarks/gem_mmap.c b/benchmarks/gem_mmap.c
index c809e08..98082ca 100644
--- a/benchmarks/gem_mmap.c
+++ b/benchmarks/gem_mmap.c
@@ -194,5 +194,6 @@ int main(int argc, char **argv)
 		printf("%7.3f\n", OBJECT_SIZE / elapsed(&start, &end) * loops / (1024*1024));
 	}
 
+	free(buf);
 	return 0;
 }
diff --git a/benchmarks/gem_syslatency.c b/benchmarks/gem_syslatency.c
index 6cad3a0..d9d2ebf 100644
--- a/benchmarks/gem_syslatency.c
+++ b/benchmarks/gem_syslatency.c
@@ -328,6 +328,8 @@ int main(int argc, char **argv)
 		break;
 	}
 
+	free(wait);
+	free(busy);
 	return 0;
 
 }
diff --git a/benchmarks/gem_userptr_benchmark.c b/benchmarks/gem_userptr_benchmark.c
index f7716df..5313f5e 100644
--- a/benchmarks/gem_userptr_benchmark.c
+++ b/benchmarks/gem_userptr_benchmark.c
@@ -355,8 +355,10 @@ static void test_impact_overlap(int fd, const char *prefix)
 
 		for (i = 0; i < nr_bos[subtest]; i++)
 			gem_close(fd, handles[i]);
-		if (block)
+		if (block) {
 			free(block);
+			block = NULL;
+		}
 	}
 }
 
diff --git a/demos/intel_sprite_on.c b/demos/intel_sprite_on.c
index 6dddded..c933d95 100644
--- a/demos/intel_sprite_on.c
+++ b/demos/intel_sprite_on.c
@@ -574,6 +574,7 @@ static void ricochet(int tiled, int sprite_w, int sprite_h,
 							  &sprite_plane_id);
 		if (!sprite_plane_count) {
 			printf("Failed to find sprite plane on crtc\n");
+			free(sprite_plane_id);
 			goto out;
 		}
 
@@ -815,6 +816,11 @@ static void ricochet(int tiled, int sprite_w, int sprite_h,
 				switch (key) {
 				case 'q':       // Kill the program
 				case 'Q':
+					free(sprite_plane_id);
+					free(sprite_x);
+					free(sprite_y);
+					free(delta_x);
+					free(delta_y);
 					goto out;
 					break;
 				case 's':       // Slow down sprite movement;
diff --git a/overlay/gpu-perf.c b/overlay/gpu-perf.c
index 42ac44d..e25adf5 100644
--- a/overlay/gpu-perf.c
+++ b/overlay/gpu-perf.c
@@ -103,8 +103,15 @@ static int perf_tracepoint_open(struct gpu_perf *gp,
 	n = gp->nr_cpus * (gp->nr_events+1);
 	fd = realloc(gp->fd, n*sizeof(int));
 	sample = realloc(gp->sample, n*sizeof(*gp->sample));
-	if (fd == NULL || sample == NULL)
+	if (fd == NULL || sample == NULL) {
+		if (fd) {
+			free(fd);
+		}
+		if (sample) {
+			free(sample);
+		}
 		return ENOMEM;
+	}
 	gp->fd = fd;
 	gp->sample = sample;
 
@@ -114,17 +121,25 @@ static int perf_tracepoint_open(struct gpu_perf *gp,
 		uint64_t track[2];
 
 		fd[n] = perf_event_open(&attr, -1, n, -1, 0);
-		if (fd[n] == -1)
+		if (fd[n] == -1) {
+			free(sample);
+			free(fd);
 			return errno;
+		}
 
 		/* read back the event to establish id->tracepoint */
-		if (read(fd[n], track, sizeof(track)) < 0)
+		if (read(fd[n], track, sizeof(track)) < 0) {
+			free(sample);
+			free(fd);
 			return errno;
+		}
 		sample[n].id = track[1];
 		sample[n].func = func;
 	}
 
 	gp->nr_events++;
+	free(sample);
+	free(fd);
 	return 0;
 }
 
diff --git a/tests/gem_render_linear_blits.c b/tests/gem_render_linear_blits.c
index 13f76a5..c01ea39 100644
--- a/tests/gem_render_linear_blits.c
+++ b/tests/gem_render_linear_blits.c
@@ -125,8 +125,11 @@ static void run_test (int fd, int count)
 	for (i = 0; i < count; i++)
 		check_bo(fd, bo[i]->handle, start_val[i]);
 
-	if (igt_run_in_simulation())
+	if (igt_run_in_simulation()) {
+		free(start_val);
+		free(bo);
 		return;
+	}
 
 	igt_info("Cyclic blits, backward...\n");
 	for (i = 0; i < count * 4; i++) {
@@ -179,6 +182,8 @@ static void run_test (int fd, int count)
 	}
 	intel_batchbuffer_free(batch);
 	drm_intel_bufmgr_destroy(bufmgr);
+	free(start_val);
+	free(bo);
 }
 
 igt_main
diff --git a/tests/gem_render_tiled_blits.c b/tests/gem_render_tiled_blits.c
index fb2f39d..ca32b8f 100644
--- a/tests/gem_render_tiled_blits.c
+++ b/tests/gem_render_tiled_blits.c
@@ -191,6 +191,8 @@ static void run_test (int fd, int count)
 	}
 	intel_batchbuffer_free(batch);
 	drm_intel_bufmgr_destroy(bufmgr);
+	free(start_val);
+	free(buf);
 }
 
 
diff --git a/tests/gem_tiled_swapping.c b/tests/gem_tiled_swapping.c
index b5849bc..d199ce1 100644
--- a/tests/gem_tiled_swapping.c
+++ b/tests/gem_tiled_swapping.c
@@ -237,4 +237,5 @@ igt_main
 	}
 
 	close(fd);
+	free(threads);
 }
diff --git a/tests/kms_atomic.c b/tests/kms_atomic.c
index f27ee46..d53a416 100644
--- a/tests/kms_atomic.c
+++ b/tests/kms_atomic.c
@@ -628,6 +628,7 @@ static void crtc_commit_legacy(struct kms_atomic_crtc_state *crtc,
 
 	crtc_check_current_state(crtc, plane, relax);
 	plane_check_current_state(plane, relax);
+	free(connectors);
 }
 
 static struct kms_atomic_crtc_state *find_crtc(struct kms_atomic_state *state,
diff --git a/tests/kms_pipe_color.c b/tests/kms_pipe_color.c
index 9f7ac7e..783925f 100644
--- a/tests/kms_pipe_color.c
+++ b/tests/kms_pipe_color.c
@@ -646,6 +646,9 @@ static void test_pipe_legacy_gamma_reset(data_t *data,
 		drmModeFreePropertyBlob(blob);
 
 		igt_output_set_pipe(output, PIPE_ANY);
+		free(blue_lut);
+		free(green_lut);
+		free(red_lut);
 	}
 
 	free(degamma_linear);
diff --git a/tests/prime_self_import.c b/tests/prime_self_import.c
index 992334d..b5673e5 100644
--- a/tests/prime_self_import.c
+++ b/tests/prime_self_import.c
@@ -281,6 +281,7 @@ static void test_reimport_close_race(void)
 	close(fake);
 
 	igt_assert_eq(obj_count, 0);
+	free(threads);
 }
 
 static void *thread_fn_export_vs_close(void *p)
@@ -362,6 +363,7 @@ static void test_export_close_race(void)
 	close(fake);
 
 	igt_assert_eq(obj_count, 0);
+	free(threads);
 }
 
 static void test_llseek_size(void)
diff --git a/tools/intel_bios_dumper.c b/tools/intel_bios_dumper.c
index 85bea97..50f2b10 100644
--- a/tools/intel_bios_dumper.c
+++ b/tools/intel_bios_dumper.c
@@ -107,6 +107,7 @@ int main(int argc, char **argv)
 
 	close(fd);
 	pci_system_cleanup();
+	free(bios);
 
 	return 0;
 }
diff --git a/tools/intel_opregion_decode.c b/tools/intel_opregion_decode.c
index c65828a..254e632 100644
--- a/tools/intel_opregion_decode.c
+++ b/tools/intel_opregion_decode.c
@@ -428,6 +428,7 @@ int main(int argc, char *argv[])
 			if (ret < 0) {
 				printf("failed to read \"%s\": %s\n", filename,
 				       strerror(errno));
+				free(opregion);
 				return 1;
 			}
 
@@ -437,6 +438,8 @@ int main(int argc, char *argv[])
 				opregion = realloc(opregion, finfo.st_size);
 			}
 		}
+		decode_opregion(opregion, finfo.st_size);
+		free(opregion);
 	} else {
 		opregion = mmap(NULL, finfo.st_size, PROT_READ, MAP_SHARED,
 				fd, 0);
@@ -445,9 +448,9 @@ int main(int argc, char *argv[])
 			       strerror(errno));
 			return 1;
 		}
+		decode_opregion(opregion, finfo.st_size);
+		munmap(opregion, finfo.st_size);
 	}
 
-	decode_opregion(opregion, finfo.st_size);
-
 	return 0;
 }
-- 
2.5.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux