grep: avoid leak of chartables in PCRE2
94da9193a6 ("grep: add support for PCRE v2", 2017-06-01) introduced
a small memory leak visible with valgrind in t7813.
Complete the creation of a PCRE2 specific variable that was missing from
the original change and free the generated table just like it is done
for PCRE1.
Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
							parent
							
								
									513f2b0bbd
								
							
						
					
					
						commit
						10da030ab7
					
				
							
								
								
									
										7
									
								
								grep.c
								
								
								
								
							
							
						
						
									
										7
									
								
								grep.c
								
								
								
								
							|  | @ -525,7 +525,6 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt | ||||||
| 	PCRE2_UCHAR errbuf[256]; | 	PCRE2_UCHAR errbuf[256]; | ||||||
| 	PCRE2_SIZE erroffset; | 	PCRE2_SIZE erroffset; | ||||||
| 	int options = PCRE2_MULTILINE; | 	int options = PCRE2_MULTILINE; | ||||||
| 	const uint8_t *character_tables = NULL; |  | ||||||
| 	int jitret; | 	int jitret; | ||||||
| 	int patinforet; | 	int patinforet; | ||||||
| 	size_t jitsizearg; | 	size_t jitsizearg; | ||||||
|  | @ -539,9 +538,10 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt | ||||||
| 		if (has_non_ascii(p->pattern)) { | 		if (has_non_ascii(p->pattern)) { | ||||||
| 			if (!pcre2_global_context) | 			if (!pcre2_global_context) | ||||||
| 				BUG("pcre2_global_context uninitialized"); | 				BUG("pcre2_global_context uninitialized"); | ||||||
| 			character_tables = pcre2_maketables(pcre2_global_context); | 			p->pcre2_tables = pcre2_maketables(pcre2_global_context); | ||||||
| 			p->pcre2_compile_context = pcre2_compile_context_create(NULL); | 			p->pcre2_compile_context = pcre2_compile_context_create(NULL); | ||||||
| 			pcre2_set_character_tables(p->pcre2_compile_context, character_tables); | 			pcre2_set_character_tables(p->pcre2_compile_context, | ||||||
|  | 							p->pcre2_tables); | ||||||
| 		} | 		} | ||||||
| 		options |= PCRE2_CASELESS; | 		options |= PCRE2_CASELESS; | ||||||
| 	} | 	} | ||||||
|  | @ -645,6 +645,7 @@ static void free_pcre2_pattern(struct grep_pat *p) | ||||||
| 	pcre2_match_data_free(p->pcre2_match_data); | 	pcre2_match_data_free(p->pcre2_match_data); | ||||||
| 	pcre2_jit_stack_free(p->pcre2_jit_stack); | 	pcre2_jit_stack_free(p->pcre2_jit_stack); | ||||||
| 	pcre2_match_context_free(p->pcre2_match_context); | 	pcre2_match_context_free(p->pcre2_match_context); | ||||||
|  | 	free((void *)p->pcre2_tables); | ||||||
| } | } | ||||||
| #else /* !USE_LIBPCRE2 */ | #else /* !USE_LIBPCRE2 */ | ||||||
| static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt) | static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt) | ||||||
|  |  | ||||||
							
								
								
									
										1
									
								
								grep.h
								
								
								
								
							
							
						
						
									
										1
									
								
								grep.h
								
								
								
								
							|  | @ -96,6 +96,7 @@ struct grep_pat { | ||||||
| 	pcre2_compile_context *pcre2_compile_context; | 	pcre2_compile_context *pcre2_compile_context; | ||||||
| 	pcre2_match_context *pcre2_match_context; | 	pcre2_match_context *pcre2_match_context; | ||||||
| 	pcre2_jit_stack *pcre2_jit_stack; | 	pcre2_jit_stack *pcre2_jit_stack; | ||||||
|  | 	const uint8_t *pcre2_tables; | ||||||
| 	uint32_t pcre2_jit_on; | 	uint32_t pcre2_jit_on; | ||||||
| 	kwset_t kws; | 	kwset_t kws; | ||||||
| 	unsigned fixed:1; | 	unsigned fixed:1; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Carlo Marcelo Arenas Belón
						Carlo Marcelo Arenas Belón