summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorMartin Pool <mbp@samba.org>2003-02-27 05:20:23 +0000
committerMartin Pool <mbp@samba.org>2003-02-27 05:20:23 +0000
commit03ae31248ee28b60600887611783efc78b1d3d59 (patch)
treeca8716dc01d160f43be7df9e6f58c33166c60bba /source3
parentfb3e4b87973e9ad0c818e8d9dd60329c47f22afe (diff)
downloadsamba-03ae31248ee28b60600887611783efc78b1d3d59.tar.gz
samba-03ae31248ee28b60600887611783efc78b1d3d59.tar.bz2
samba-03ae31248ee28b60600887611783efc78b1d3d59.zip
Merge 1.100 patch from HEAD:
init_valid_table: Fix a memory leak that would lose the dynamically-created valid table every time the configuration was reloaded. (This used to be commit 3ff4845bc43736bfa091419c80b9a0ebdc9d156e)
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/util_unistr.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c
index 522ab7eb40..c666155f9f 100644
--- a/source3/lib/util_unistr.c
+++ b/source3/lib/util_unistr.c
@@ -105,27 +105,34 @@ static int check_dos_char(smb_ucs2_t c)
**/
void init_valid_table(void)
{
- static int initialised;
static int mapped_file;
int i;
const char *allowed = ".!#$%&'()_-@^`~";
+ uint8 *valid_file;
- if (initialised && mapped_file) return;
- initialised = 1;
+ if (mapped_file) {
+ /* Can't unmap files, so stick with what we have */
+ return;
+ }
- valid_table = map_file(lib_path("valid.dat"), 0x10000);
- if (valid_table) {
+ valid_file = map_file(lib_path("valid.dat"), 0x10000);
+ if (valid_file) {
+ valid_table = valid_file;
mapped_file = 1;
return;
}
- /* Otherwise, using a dynamically loaded one. */
+ /* Otherwise, we're using a dynamically created valid_table.
+ * It might need to be regenerated if the code page changed.
+ * We know that we're not using a mapped file, so we can
+ * free() the old one. */
if (valid_table) free(valid_table);
DEBUG(2,("creating default valid table\n"));
valid_table = malloc(0x10000);
- for (i=0;i<128;i++) valid_table[i] = isalnum(i) ||
- strchr(allowed,i);
+ for (i=0;i<128;i++)
+ valid_table[i] = isalnum(i) || strchr(allowed,i);
+
for (;i<0x10000;i++) {
smb_ucs2_t c;
SSVAL(&c, 0, i);