[PATCH v5] app/mldev: add internal function for file read

Stephen Hemminger stephen at networkplumber.org
Wed Jun 7 18:49:21 CEST 2023


On Wed, 7 Jun 2023 09:20:30 -0700
Srikanth Yalavarthi <syalavarthi at marvell.com> wrote:
The normal case leaks the open file descriptor

+
+	file_map = mmap(0, file_stat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+	if (file_map == MAP_FAILED) {
+		ml_err("Failed to map file: %s\n", file);
+		ret = -errno;
+		goto error;
+	}
+
+	rte_memcpy(file_buffer, file_map, file_stat.st_size);
+	munmap(file_map, file_stat.st_size);
+
+	*size = file_stat.st_size;
+	*buffer = file_buffer;
+
+	return 0;

Missing close()

> +	if (buffer)
> +		free(buffer);
> +

Another needless if()



More information about the dev mailing list