Skip to contentSkip to conversation

tools/vm: Fix possible resource leak in page_owner_sort.c

PATCH New Saurabh Badhwar 1 participant 1 message Feb 20, 2017 Kernel janitors

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tools/vm: Fix possible resource leak in page_owner_sort.c

The patch addresses explicit closing of file pointers on exit and redirects the errors to the stderr

---
 tools/vm/page_owner_sort.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/vm/page_owner_sort.c +3 -3
index 8346261..b3c3efa 100644
@@ -109,7 +109,7 @@ int main(int argc, char **argv)
 	list = malloc(max_size * sizeof(*list));
 	buf = malloc(BUF_SIZE);
 	if (!list || !buf) {
-		printf("Out of memory\n");
+		perror("Unable to allocate memory: ");
 		fclose(fin);
 		fclose(fout);
 		exit(1);
@@ -145,8 +145,8 @@ int main(int argc, char **argv)
 	qsort(list2, count, sizeof(list[0]), compare_num);
 
 	for (i = 0; i < count; i++)
-		fprintf(fout, "%d times:\n%s\n", list2[i].num, list2[i].txt);
-		
+		fprintf(fout, "%d times:\n%s\n", list2[i].num, list2[i].txt);	
+	
 	fclose(fout);
 	return 0;
 }
Signature · 1 line
2.9.3