diff options
author | kaie%kuix.de <devnull@localhost> | 2012-11-14 17:16:50 +0000 |
---|---|---|
committer | kaie%kuix.de <devnull@localhost> | 2012-11-14 17:16:50 +0000 |
commit | cd931cba7e336a0c2a09f290323677d2bb782903 (patch) | |
tree | 9bcd7991c0899fcd99219df1d370ddbc226b091c | |
parent | d2c8e0506a7764245772e835d4d6900b018875cd (diff) | |
download | nss-hg-cd931cba7e336a0c2a09f290323677d2bb782903.tar.gz |
Bug 578561, sdb_getTempDir returns NULL with new versions of sqlite, r=rrelyea + suggested modification
-rw-r--r-- | security/nss/lib/softoken/sdb.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/security/nss/lib/softoken/sdb.c b/security/nss/lib/softoken/sdb.c index c6ff11037..5b4e232f5 100644 --- a/security/nss/lib/softoken/sdb.c +++ b/security/nss/lib/softoken/sdb.c @@ -1821,6 +1821,7 @@ sdb_init(char *dbname, char *table, sdbDataType type, int *inUpdate, enableCache = PR_TRUE; } else { char *tempDir = NULL; + PRBool mustFreeTempDir = PR_TRUE; PRUint32 tempOps = 0; /* * Use PR_Access to determine how expensive it @@ -1828,14 +1829,37 @@ sdb_init(char *dbname, char *table, sdbDataType type, int *inUpdate, * check in the temp directory. If the temp directory is faster, cache * the database there. */ tempDir = sdb_getTempDir(sqlDB); + + if (!tempDir) { + mustFreeTempDir = PR_FALSE; /* getenv will return references */ + tempDir = getenv("TEMP"); + if (!tempDir) + tempDir = getenv("TMP"); + if (!tempDir) { + tempDir = tempnam(NULL, NULL); + if (tempDir) { + mustFreeTempDir = PR_TRUE; + char dirsep = PR_GetDirectorySeparator(); + char *end = PORT_Strrchr(tempDir, dirsep); + if (end) { + /* We shorten the temp filename string to contain + * only the directory name. + */ + *end = 0; + } + } + } + } + if (tempDir) { tempOps = sdb_measureAccess(tempDir); - PORT_Free(tempDir); /* There is a cost to continually copying the database. * Account for that cost with the arbitrary factor of 10 */ enableCache = (PRBool)(tempOps > accessOps * 10); } + if (mustFreeTempDir) + PORT_Free(tempDir); } if (enableCache) { |