diff options
author | Werner Koch <wk@gnupg.org> | 2010-12-14 20:17:58 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2010-12-14 20:17:58 +0100 |
commit | 5fd7ff3488d64cddad9b0f767ef21059fe52be71 (patch) | |
tree | 5706364bf2658b80debc0f0f5d93a88b4f924534 /dirmngr | |
parent | Change --dameon home directory to /gnupg under Wince (diff) | |
download | gnupg2-5fd7ff3488d64cddad9b0f767ef21059fe52be71.tar.xz gnupg2-5fd7ff3488d64cddad9b0f767ef21059fe52be71.zip |
Tweaks for gpgconf.
Fixed dirmngr bug 1010.
Diffstat (limited to 'dirmngr')
-rw-r--r-- | dirmngr/ChangeLog | 7 | ||||
-rw-r--r-- | dirmngr/cdb.h | 3 | ||||
-rw-r--r-- | dirmngr/cdblib.c | 17 | ||||
-rw-r--r-- | dirmngr/crlcache.c | 31 |
4 files changed, 43 insertions, 15 deletions
diff --git a/dirmngr/ChangeLog b/dirmngr/ChangeLog index 11fd1b7f1..2c208755d 100644 --- a/dirmngr/ChangeLog +++ b/dirmngr/ChangeLog @@ -1,5 +1,12 @@ 2010-12-14 Werner Koch <wk@g10code.com> + * cdb.h (struct cdb) [W32]: Add field CDB_MAPPING. + * cdblib.c (cdb_init) [W32]: Save mapping handle. + (cdb_free) [W32]: Don't leak the mapping handle from cdb_init by + using the saved one. + + * crlcache.c (crl_cache_insert): Close unused matching files. + * dirmngr.c (main) [W32CE]: Change homedir in daemon mode to /gnupg. 2010-12-07 Werner Koch <wk@g10code.com> diff --git a/dirmngr/cdb.h b/dirmngr/cdb.h index 73cc9952e..0c0d2702a 100644 --- a/dirmngr/cdb.h +++ b/dirmngr/cdb.h @@ -20,6 +20,9 @@ void cdb_pack(cdbi_t num, unsigned char buf[4]); struct cdb { int cdb_fd; /* file descriptor */ /* private members */ +#ifdef HAVE_W32_SYSTEM + void *cdb_mapping; /* Mapping handle. */ +#endif cdbi_t cdb_fsize; /* datafile size */ const unsigned char *cdb_mem; /* mmap'ed file memory */ cdbi_t cdb_vpos, cdb_vlen; /* found data */ diff --git a/dirmngr/cdblib.c b/dirmngr/cdblib.c index 16d53aed8..3bfeffc11 100644 --- a/dirmngr/cdblib.c +++ b/dirmngr/cdblib.c @@ -135,7 +135,7 @@ cdb_init(struct cdb *cdbp, int fd) hFile = fd; # else hFile = (HANDLE) _get_osfhandle(fd); -#endif +# endif if (hFile == (HANDLE) -1) return -1; hMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); @@ -144,6 +144,7 @@ cdb_init(struct cdb *cdbp, int fd) mem = (unsigned char *)MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0); if (!mem) return -1; + cdbp->cdb_mapping = hMapping; #else mem = (unsigned char*)mmap(NULL, fsize, PROT_READ, MAP_SHARED, fd, 0); if (mem == MAP_FAILED) @@ -180,17 +181,9 @@ cdb_free(struct cdb *cdbp) { if (cdbp->cdb_mem) { #ifdef _WIN32 - HANDLE hFile, hMapping; -#endif -#ifdef _WIN32 -#ifdef __MINGW32CE__ - hFile = cdbp->cdb_fd; -#else - hFile = (HANDLE) _get_osfhandle(cdbp->cdb_fd); -#endif - hMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); - UnmapViewOfFile((void*) cdbp->cdb_mem); - CloseHandle(hMapping); + UnmapViewOfFile ((void*) cdbp->cdb_mem); + CloseHandle (cdbp->cdb_mapping); + cdbp->cdb_mapping = NULL; #else munmap((void*)cdbp->cdb_mem, cdbp->cdb_fsize); #endif /* _WIN32 */ diff --git a/dirmngr/crlcache.c b/dirmngr/crlcache.c index 5f0430525..12d451060 100644 --- a/dirmngr/crlcache.c +++ b/dirmngr/crlcache.c @@ -178,7 +178,7 @@ static crl_cache_entry_t find_entry (crl_cache_entry_t first, -/* The currently loaded cache object. This isi usually initialized +/* The currently loaded cache object. This is usually initialized right at startup. */ static crl_cache_t current_cache; @@ -393,7 +393,7 @@ release_cache (crl_cache_t cache) { entry2 = entry->next; release_one_cache_entry (entry); - } + } cache->entries = NULL; xfree (cache); } @@ -1189,6 +1189,7 @@ unlock_db_file (crl_cache_t cache, crl_cache_entry_t entry) cache->entries = enext; else eprev->next = enext; + /* FIXME: Do we leak ENTRY? */ } } @@ -1204,7 +1205,6 @@ find_entry (crl_cache_entry_t first, const char *issuer_hash) } - /* Create a new CRL cache. This fucntion is usually called only once. never fail. */ void @@ -2177,6 +2177,31 @@ crl_cache_insert (ctrl_t ctrl, const char *url, ksba_reader_t reader) newfname = make_db_file_name (entry->issuer_hash); if (opt.verbose) log_info (_("creating cache file `%s'\n"), newfname); + + /* Just in case close unused matching files. Actually we need this + only under Windows but saving file descriptors is never bad. */ + { + int any; + do + { + any = 0; + for (e = cache->entries; e; e = e->next) + if (!e->cdb_use_count && e->cdb + && !strcmp (e->issuer_hash, entry->issuer_hash)) + { + int fd = cdb_fileno (e->cdb); + cdb_free (e->cdb); + xfree (e->cdb); + e->cdb = NULL; + if (close (fd)) + log_error (_("error closing cache file: %s\n"), + strerror(errno)); + any = 1; + break; + } + } + while (any); + } #ifdef HAVE_W32_SYSTEM gnupg_remove (newfname); #endif |