summaryrefslogtreecommitdiff
path: root/source3/lib/util_unistr.c
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2006-04-08 17:25:31 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:15:55 -0500
commitbbf666e447132a5f6b206ddf9ca918298b756392 (patch)
tree3cac70deddd159edbd7fb3aece639c48e9a5e67e /source3/lib/util_unistr.c
parentc9c502442b40aba97de17456ba948effcdfa3d05 (diff)
downloadsamba-bbf666e447132a5f6b206ddf9ca918298b756392.tar.gz
samba-bbf666e447132a5f6b206ddf9ca918298b756392.tar.bz2
samba-bbf666e447132a5f6b206ddf9ca918298b756392.zip
r15003: patch based on code from Arkady Glabek <aglabek@centeris.com> to ensure that global memory is freed when unloading pam_winbind.so (needs more testing on non-linux platforms)
(This used to be commit 1e0b79e591d70352a96e0a0487d8f394dc7b36ba)
Diffstat (limited to 'source3/lib/util_unistr.c')
-rw-r--r--source3/lib/util_unistr.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c
index 9713c0ccb7..eef484148d 100644
--- a/source3/lib/util_unistr.c
+++ b/source3/lib/util_unistr.c
@@ -31,6 +31,9 @@
static smb_ucs2_t *upcase_table;
static smb_ucs2_t *lowcase_table;
static uint8 *valid_table;
+static BOOL upcase_table_use_unmap;
+static BOOL lowcase_table_use_unmap;
+static BOOL valid_table_use_unmap;
/**
* This table says which Unicode characters are valid dos
@@ -40,6 +43,32 @@ static uint8 *valid_table;
**/
static uint8 doschar_table[8192]; /* 65536 characters / 8 bits/byte */
+/**
+ * Destroy global objects allocated by load_case_tables()
+ **/
+void gfree_case_tables(void)
+{
+ if ( upcase_table ) {
+ if ( upcase_table_use_unmap )
+ unmap_file(upcase_table, 0x20000);
+ else
+ SAFE_FREE(upcase_table);
+ }
+
+ if ( lowcase_table ) {
+ if ( lowcase_table_use_unmap )
+ unmap_file(lowcase_table, 0x20000);
+ else
+ SAFE_FREE(lowcase_table);
+ }
+
+ if ( valid_table ) {
+ if ( valid_table_use_unmap )
+ unmap_file(valid_table, 0x10000);
+ else
+ SAFE_FREE(valid_table);
+ }
+}
/**
* Load or generate the case handling tables.
@@ -60,7 +89,10 @@ void load_case_tables(void)
initialised = 1;
upcase_table = map_file(lib_path("upcase.dat"), 0x20000);
+ upcase_table_use_unmap = ( upcase_table != NULL );
+
lowcase_table = map_file(lib_path("lowcase.dat"), 0x20000);
+ lowcase_table_use_unmap = ( lowcase_table != NULL );
#ifdef HAVE_SETLOCALE
/* Get the name of the current locale. */
@@ -196,6 +228,7 @@ void init_valid_table(void)
if (valid_file) {
valid_table = valid_file;
mapped_file = 1;
+ valid_table_use_unmap = True;
return;
}
@@ -203,7 +236,11 @@ void init_valid_table(void)
* 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);
+ if (valid_table)
+ SAFE_FREE(valid_table);
+
+ /* use free rather than unmap */
+ valid_table_use_unmap = False;
DEBUG(2,("creating default valid table\n"));
valid_table = SMB_MALLOC(0x10000);