diff options
| author | Junio C Hamano <gitster@pobox.com> | 2024-05-29 09:32:24 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-05-29 09:32:24 -0700 |
| commit | 5529cba09ff89b9762dbfd8f622e897948b60ab7 (patch) | |
| tree | 3fad1f1ce36df7d8328a1a3c43a4dd41e37526a8 /diff.c | |
| parent | The eighth batch (diff) | |
| parent | builtin/mv: fix leaks for submodule gitfile paths (diff) | |
| download | git-5529cba09ff89b9762dbfd8f622e897948b60ab7.tar.gz git-5529cba09ff89b9762dbfd8f622e897948b60ab7.zip | |
Merge branch 'ps/leakfixes' into ps/no-writable-strings
* ps/leakfixes:
builtin/mv: fix leaks for submodule gitfile paths
builtin/mv: refactor to use `struct strvec`
builtin/mv duplicate string list memory
builtin/mv: refactor `add_slash()` to always return allocated strings
strvec: add functions to replace and remove strings
submodule: fix leaking memory for submodule entries
commit-reach: fix memory leak in `ahead_behind()`
builtin/credential: clear credential before exit
config: plug various memory leaks
config: clarify memory ownership in `git_config_string()`
builtin/log: stop using globals for format config
builtin/log: stop using globals for log config
convert: refactor code to clarify ownership of check_roundtrip_encoding
diff: refactor code to clarify memory ownership of prefixes
config: clarify memory ownership in `git_config_pathname()`
http: refactor code to clarify memory ownership
checkout: clarify memory ownership in `unique_tracking_name()`
strbuf: fix leak when `appendwholeline()` fails with EOF
transport-helper: fix leaking helper name
Diffstat (limited to 'diff.c')
| -rw-r--r-- | diff.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -56,14 +56,14 @@ static int diff_color_moved_default; static int diff_color_moved_ws_default; static int diff_context_default = 3; static int diff_interhunk_context_default; -static const char *diff_word_regex_cfg; -static const char *external_diff_cmd_cfg; -static const char *diff_order_file_cfg; +static char *diff_word_regex_cfg; +static char *external_diff_cmd_cfg; +static char *diff_order_file_cfg; int diff_auto_refresh_index = 1; static int diff_mnemonic_prefix; static int diff_no_prefix; -static const char *diff_src_prefix = "a/"; -static const char *diff_dst_prefix = "b/"; +static char *diff_src_prefix; +static char *diff_dst_prefix; static int diff_relative; static int diff_stat_name_width; static int diff_stat_graph_width; @@ -411,9 +411,11 @@ int git_diff_ui_config(const char *var, const char *value, return 0; } if (!strcmp(var, "diff.srcprefix")) { + FREE_AND_NULL(diff_src_prefix); return git_config_string(&diff_src_prefix, var, value); } if (!strcmp(var, "diff.dstprefix")) { + FREE_AND_NULL(diff_dst_prefix); return git_config_string(&diff_dst_prefix, var, value); } if (!strcmp(var, "diff.relative")) { @@ -3433,8 +3435,8 @@ void diff_set_noprefix(struct diff_options *options) void diff_set_default_prefix(struct diff_options *options) { - options->a_prefix = diff_src_prefix; - options->b_prefix = diff_dst_prefix; + options->a_prefix = diff_src_prefix ? diff_src_prefix : "a/"; + options->b_prefix = diff_dst_prefix ? diff_dst_prefix : "b/"; } struct userdiff_driver *get_textconv(struct repository *r, @@ -5371,8 +5373,8 @@ static int diff_opt_default_prefix(const struct option *opt, BUG_ON_OPT_NEG(unset); BUG_ON_OPT_ARG(optarg); - diff_src_prefix = "a/"; - diff_dst_prefix = "b/"; + FREE_AND_NULL(diff_src_prefix); + FREE_AND_NULL(diff_dst_prefix); diff_set_default_prefix(options); return 0; } |
