Skip to content

Commit 3b82542

Browse files
Martin Ågrengitster
authored andcommitted
config: let config_store_data_clear() handle value_regex
Instead of duplicating the logic for clearing up `value_regex`, let `config_store_data_clear()` handle that. When `regcomp()` fails, the current code does not call `regfree()`. Make sure we do the same by immediately invalidating `value_regex`. Some implementations are able to handle such an extra `regfree()`-call [1], but from the example in [2], we should not do so. (The language itself in [2] is not super-clear on this.) [1] https://www.redhat.com/archives/libvir-list/2013-September/msg00262.html [2] http://pubs.opengroup.org/onlinepubs/9699919799/functions/regcomp.html Researched-by: Eric Sunshine <[email protected]> Signed-off-by: Martin Ågren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2a00e59 commit 3b82542

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

config.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,6 +2335,11 @@ struct config_store_data {
23352335

23362336
static void config_store_data_clear(struct config_store_data *store)
23372337
{
2338+
if (store->value_regex != NULL &&
2339+
store->value_regex != CONFIG_REGEX_NONE) {
2340+
regfree(store->value_regex);
2341+
free(store->value_regex);
2342+
}
23382343
free(store->parsed);
23392344
free(store->seen);
23402345
memset(store, 0, sizeof(*store));
@@ -2722,7 +2727,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
27222727
if (regcomp(store.value_regex, value_regex,
27232728
REG_EXTENDED)) {
27242729
error("invalid pattern: %s", value_regex);
2725-
free(store.value_regex);
2730+
FREE_AND_NULL(store.value_regex);
27262731
ret = CONFIG_INVALID_PATTERN;
27272732
goto out_free;
27282733
}
@@ -2748,21 +2753,11 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
27482753
&store, &opts)) {
27492754
error("invalid config file %s", config_filename);
27502755
free(store.key);
2751-
if (store.value_regex != NULL &&
2752-
store.value_regex != CONFIG_REGEX_NONE) {
2753-
regfree(store.value_regex);
2754-
free(store.value_regex);
2755-
}
27562756
ret = CONFIG_INVALID_FILE;
27572757
goto out_free;
27582758
}
27592759

27602760
free(store.key);
2761-
if (store.value_regex != NULL &&
2762-
store.value_regex != CONFIG_REGEX_NONE) {
2763-
regfree(store.value_regex);
2764-
free(store.value_regex);
2765-
}
27662761

27672762
/* if nothing to unset, or too many matches, error out */
27682763
if ((store.seen_nr == 0 && value == NULL) ||

0 commit comments

Comments
 (0)