summaryrefslogtreecommitdiffstats
path: root/source3/lib/ms_fnmatch.c
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2008-02-01 14:24:31 -0500
committerSimo Sorce <idra@samba.org>2008-02-01 14:24:31 -0500
commit2fffc9a1b1fe2a1490e867bb38462e50c282d2b3 (patch)
tree428e09c9b35138db8b7ca7161c659a71aa129d29 /source3/lib/ms_fnmatch.c
parent93a3c5b3f9927973b4ad1496f593ea147052d1e1 (diff)
parentb708005a7106db26d7df689b887b419c9f2ea41c (diff)
downloadsamba-2fffc9a1b1fe2a1490e867bb38462e50c282d2b3.tar.gz
samba-2fffc9a1b1fe2a1490e867bb38462e50c282d2b3.tar.xz
samba-2fffc9a1b1fe2a1490e867bb38462e50c282d2b3.zip
Merge branch 'v3-2-test' of ssh://git.samba.org/data/git/samba into v3-2-test
(This used to be commit 7dbfc7bdc65314466a83e8121b35c9bcb24b2631)
Diffstat (limited to 'source3/lib/ms_fnmatch.c')
-rw-r--r--source3/lib/ms_fnmatch.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/source3/lib/ms_fnmatch.c b/source3/lib/ms_fnmatch.c
index a839b42588..8b69f1c2d2 100644
--- a/source3/lib/ms_fnmatch.c
+++ b/source3/lib/ms_fnmatch.c
@@ -152,6 +152,8 @@ int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern,
smb_ucs2_t *s = NULL;
int ret, count, i;
struct max_n *max_n = NULL;
+ struct max_n *max_n_free = NULL;
+ struct max_n one_max_n;
if (ISDOTDOT(string)) {
string = ".";
@@ -201,17 +203,27 @@ int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern,
}
if (count != 0) {
- max_n = SMB_CALLOC_ARRAY(struct max_n, count);
- if (!max_n) {
- SAFE_FREE(p);
- SAFE_FREE(s);
- return -1;
+ if (count == 1) {
+ /*
+ * We're doing this a LOT, so save the effort to allocate
+ */
+ ZERO_STRUCT(one_max_n);
+ max_n = &one_max_n;
+ }
+ else {
+ max_n = SMB_CALLOC_ARRAY(struct max_n, count);
+ if (!max_n) {
+ SAFE_FREE(p);
+ SAFE_FREE(s);
+ return -1;
+ }
+ max_n_free = max_n;
}
}
ret = ms_fnmatch_core(p, s, max_n, strrchr_w(s, UCS2_CHAR('.')), is_case_sensitive);
- SAFE_FREE(max_n);
+ SAFE_FREE(max_n_free);
SAFE_FREE(p);
SAFE_FREE(s);
return ret;