Commit 5623e627 by Anurag Gupta (OSG) Committed by Edward Thomson

git_filter: dup the filter name

parent dfff1b5b
...@@ -38,7 +38,7 @@ struct git_filter_list { ...@@ -38,7 +38,7 @@ struct git_filter_list {
}; };
typedef struct { typedef struct {
const char *filter_name; char *filter_name;
git_filter *filter; git_filter *filter;
int priority; int priority;
int initialized; int initialized;
...@@ -75,6 +75,7 @@ static void filter_registry_shutdown(void) ...@@ -75,6 +75,7 @@ static void filter_registry_shutdown(void)
fdef->initialized = false; fdef->initialized = false;
} }
git__free(fdef->filter_name);
git__free(fdef->attrdata); git__free(fdef->attrdata);
git__free(fdef); git__free(fdef);
} }
...@@ -230,6 +231,8 @@ int git_filter_register( ...@@ -230,6 +231,8 @@ int git_filter_register(
size_t nattr = 0, nmatch = 0; size_t nattr = 0, nmatch = 0;
git_buf attrs = GIT_BUF_INIT; git_buf attrs = GIT_BUF_INIT;
assert(name && filter);
if (filter_registry_initialize() < 0) if (filter_registry_initialize() < 0)
return -1; return -1;
...@@ -246,7 +249,9 @@ int git_filter_register( ...@@ -246,7 +249,9 @@ int git_filter_register(
sizeof(git_filter_def) + 2 * nattr * sizeof(char *), 1); sizeof(git_filter_def) + 2 * nattr * sizeof(char *), 1);
GITERR_CHECK_ALLOC(fdef); GITERR_CHECK_ALLOC(fdef);
fdef->filter_name = name; fdef->filter_name = git__strdup(name);
GITERR_CHECK_ALLOC(fdef->filter_name);
fdef->filter = filter; fdef->filter = filter;
fdef->priority = priority; fdef->priority = priority;
fdef->nattrs = nattr; fdef->nattrs = nattr;
...@@ -256,6 +261,7 @@ int git_filter_register( ...@@ -256,6 +261,7 @@ int git_filter_register(
filter_def_set_attrs(fdef); filter_def_set_attrs(fdef);
if (git_vector_insert(&git__filter_registry->filters, fdef) < 0) { if (git_vector_insert(&git__filter_registry->filters, fdef) < 0) {
git__free(fdef->filter_name);
git__free(fdef->attrdata); git__free(fdef->attrdata);
git__free(fdef); git__free(fdef);
return -1; return -1;
...@@ -270,6 +276,8 @@ int git_filter_unregister(const char *name) ...@@ -270,6 +276,8 @@ int git_filter_unregister(const char *name)
size_t pos; size_t pos;
git_filter_def *fdef; git_filter_def *fdef;
assert(name);
/* cannot unregister default filters */ /* cannot unregister default filters */
if (!strcmp(GIT_FILTER_CRLF, name) || !strcmp(GIT_FILTER_IDENT, name)) { if (!strcmp(GIT_FILTER_CRLF, name) || !strcmp(GIT_FILTER_IDENT, name)) {
giterr_set(GITERR_FILTER, "Cannot unregister filter '%s'", name); giterr_set(GITERR_FILTER, "Cannot unregister filter '%s'", name);
...@@ -288,6 +296,7 @@ int git_filter_unregister(const char *name) ...@@ -288,6 +296,7 @@ int git_filter_unregister(const char *name)
fdef->initialized = false; fdef->initialized = false;
} }
git__free(fdef->filter_name);
git__free(fdef->attrdata); git__free(fdef->attrdata);
git__free(fdef); git__free(fdef);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment