From 040a655116c9755bbf30acd22c34eecb2f502c6d Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 6 Oct 2011 13:22:22 -0500 Subject: cleanup: use internal memory allocation wrapper functions everywhere The "x"-prefixed versions of strdup, malloc, etc. will check whether the allocation was successful and terminate the process otherwise. A few uses of malloc were left alone since they already implemented a graceful path of failure or were in a quasi external library like xdiff. Additionally, the call to malloc in compat/win32/syslog.c was not modified since the syslog() implemented there is a die handler and a call to the x-wrappers within a die handler could result in recursion should memory allocation fail. This will have to be addressed separately. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- builtin/mv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/mv.c b/builtin/mv.c index 40f33ca4d0..e9d191f056 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -29,7 +29,7 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec, to_copy--; if (to_copy != length || base_name) { char *it = xmemdupz(result[i], to_copy); - result[i] = base_name ? strdup(basename(it)) : it; + result[i] = base_name ? xstrdup(basename(it)) : it; } } return get_pathspec(prefix, result); -- cgit v1.2.3 From 0d0ff65cea5424a202510fa4e28a461d36032276 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 6 Oct 2011 13:22:23 -0500 Subject: builtin/mv.c: plug miniscule memory leak The "it" string would not be free'ed if base_name was non-NULL. Let's free it. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- builtin/mv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/mv.c b/builtin/mv.c index e9d191f056..5efe6c5760 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -29,7 +29,11 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec, to_copy--; if (to_copy != length || base_name) { char *it = xmemdupz(result[i], to_copy); - result[i] = base_name ? xstrdup(basename(it)) : it; + if (base_name) { + result[i] = xstrdup(basename(it)); + free(it); + } else + result[i] = it; } } return get_pathspec(prefix, result); -- cgit v1.2.3 From 64589a03a8ffb3eb4fb2ff8f416ff638a9aaa439 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 6 Oct 2011 13:22:24 -0500 Subject: attr: read core.attributesfile from git_default_core_config This code calls git_config from a helper function to parse the config entry it is interested in. Calling git_config in this way may cause a problem if the helper function can be called after a previous call to git_config by another function since the second call to git_config may reset some variable to the value in the config file which was previously overridden. The above is not a problem in this case since the function passed to git_config only parses one config entry and the variable it sets is not assigned outside of the parsing function. But a programmer who desires all of the standard config options to be parsed may be tempted to modify git_attr_config() so that it falls back to git_default_config() and then it _would_ be vulnerable to the above described behavior. So, move the call to git_config up into the top-level cmd_* function and move the responsibility for parsing core.attributesfile into the main config file parser. Which is only the logical thing to do ;-) Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- builtin/check-attr.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'builtin') diff --git a/builtin/check-attr.c b/builtin/check-attr.c index 708988a0e1..abb11650fd 100644 --- a/builtin/check-attr.c +++ b/builtin/check-attr.c @@ -92,6 +92,8 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix) struct git_attr_check *check; int cnt, i, doubledash, filei; + git_config(git_default_config, NULL); + argc = parse_options(argc, argv, prefix, check_attr_options, check_attr_usage, PARSE_OPT_KEEP_DASHDASH); -- cgit v1.2.3