You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found when I MMDB_close a database, I can't actually delete the file until the process completes. Looking at the code, in the cleanup: code in map_file, based on Microsoft Windows documentation, I believe you should always close the mmh handle (not just on failure). If you successfully get the mmh, and MapViewOfFile to that mmh, then I think their docs say you can close the mmh, since the view will keep the file mapped and locked. Changed lines shown below.
cleanup:;
int saved_errno = errno;
ifdef _WIN32
if (INVALID_HANDLE_VALUE != fd) {
CloseHandle(fd);
}
if (INVALID_HANDLE_VALUE != mmh) {
CloseHandle(mmh);
}
else
Secondly, looking at the WSAStartup and WSACleanup logic, In MMDB_open, I think you should actually do the WSAStartup if map_file returns successful, and not further down in that function. The MMDB_close() calls WSACleanup() if mmdb->file_content is not NULL, so you should make sure you call WSAStartup any time you have a valid mmdb->file_content, which is as soon as map_file() returns successfully.
I.e. I moved the WSAStartup earlier in MMDB_open...
I found when I MMDB_close a database, I can't actually delete the file until the process completes. Looking at the code, in the cleanup: code in map_file, based on Microsoft Windows documentation, I believe you should always close the mmh handle (not just on failure). If you successfully get the mmh, and MapViewOfFile to that mmh, then I think their docs say you can close the mmh, since the view will keep the file mapped and locked. Changed lines shown below.
cleanup:;
int saved_errno = errno;
ifdef _WIN32
Secondly, looking at the WSAStartup and WSACleanup logic, In MMDB_open, I think you should actually do the WSAStartup if map_file returns successful, and not further down in that function. The MMDB_close() calls WSACleanup() if mmdb->file_content is not NULL, so you should make sure you call WSAStartup any time you have a valid mmdb->file_content, which is as soon as map_file() returns successfully.
I.e. I moved the WSAStartup earlier in MMDB_open...
Is it easier if I create a pull request to describe this?
I can also email you an updated maxminddb.c file if you would like to look at it.
Thanks.
Bly
The text was updated successfully, but these errors were encountered: