mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	lib subcmd: Avoid memory leak in exclude_cmds
exclude_cmds will shorten the cmds names array, before doing so free the removed entry. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: André Almeida <andrealmeid@igalia.com> Cc: Darren Hart <dvhart@infradead.org> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20230611233610.953456-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
		
							parent
							
								
									d927ef5004
								
							
						
					
					
						commit
						657a3efee4
					
				
					 1 changed files with 6 additions and 2 deletions
				
			
		| 
						 | 
					@ -66,6 +66,7 @@ void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes)
 | 
				
			||||||
	while (ci < cmds->cnt && ei < excludes->cnt) {
 | 
						while (ci < cmds->cnt && ei < excludes->cnt) {
 | 
				
			||||||
		cmp = strcmp(cmds->names[ci]->name, excludes->names[ei]->name);
 | 
							cmp = strcmp(cmds->names[ci]->name, excludes->names[ei]->name);
 | 
				
			||||||
		if (cmp < 0) {
 | 
							if (cmp < 0) {
 | 
				
			||||||
 | 
								zfree(&cmds->names[cj]);
 | 
				
			||||||
			cmds->names[cj++] = cmds->names[ci++];
 | 
								cmds->names[cj++] = cmds->names[ci++];
 | 
				
			||||||
		} else if (cmp == 0) {
 | 
							} else if (cmp == 0) {
 | 
				
			||||||
			ci++;
 | 
								ci++;
 | 
				
			||||||
| 
						 | 
					@ -75,9 +76,12 @@ void exclude_cmds(struct cmdnames *cmds, struct cmdnames *excludes)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while (ci < cmds->cnt)
 | 
						while (ci < cmds->cnt) {
 | 
				
			||||||
 | 
							zfree(&cmds->names[cj]);
 | 
				
			||||||
		cmds->names[cj++] = cmds->names[ci++];
 | 
							cmds->names[cj++] = cmds->names[ci++];
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for (ci = cj; ci < cmds->cnt; ci++)
 | 
				
			||||||
 | 
							zfree(&cmds->names[ci]);
 | 
				
			||||||
	cmds->cnt = cj;
 | 
						cmds->cnt = cj;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue