mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-21 15:19:34 -05:00
Clean up MAP_FAILED handling in mdb.
Delay (MDB_txninfo*) cast to after comparing mmap() with MAP_FAILED. Otherwise, if MAP_FAILED = (void*)-1 but MDB_txninfo requires stricter alignment, the compiler could assume the result is never MAP_FAILED. Also store NULL in env->(me_map, me_txns) after mmap failure.
This commit is contained in:
parent
2baadabdff
commit
d3b9939e71
1 changed files with 13 additions and 9 deletions
|
|
@ -2389,8 +2389,10 @@ mdb_env_open2(MDB_env *env, unsigned int flags)
|
||||||
i |= MAP_FIXED;
|
i |= MAP_FIXED;
|
||||||
env->me_map = mmap(meta.mm_address, env->me_mapsize, PROT_READ, i,
|
env->me_map = mmap(meta.mm_address, env->me_mapsize, PROT_READ, i,
|
||||||
env->me_fd, 0);
|
env->me_fd, 0);
|
||||||
if (env->me_map == MAP_FAILED)
|
if (env->me_map == MAP_FAILED) {
|
||||||
|
env->me_map = NULL;
|
||||||
return ErrCode();
|
return ErrCode();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (newenv) {
|
if (newenv) {
|
||||||
|
|
@ -2639,8 +2641,8 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl)
|
||||||
size = rsize - sizeof(MDB_txninfo);
|
size = rsize - sizeof(MDB_txninfo);
|
||||||
env->me_maxreaders = size/sizeof(MDB_reader) + 1;
|
env->me_maxreaders = size/sizeof(MDB_reader) + 1;
|
||||||
}
|
}
|
||||||
#ifdef _WIN32
|
|
||||||
{
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
HANDLE mh;
|
HANDLE mh;
|
||||||
mh = CreateFileMapping(env->me_lfd, NULL, PAGE_READWRITE,
|
mh = CreateFileMapping(env->me_lfd, NULL, PAGE_READWRITE,
|
||||||
0, 0, NULL);
|
0, 0, NULL);
|
||||||
|
|
@ -2654,15 +2656,17 @@ mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl)
|
||||||
rc = ErrCode();
|
rc = ErrCode();
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
env->me_txns = (MDB_txninfo *)mmap(0, rsize, PROT_READ|PROT_WRITE, MAP_SHARED,
|
void *m = mmap(NULL, rsize, PROT_READ|PROT_WRITE, MAP_SHARED,
|
||||||
env->me_lfd, 0);
|
env->me_lfd, 0);
|
||||||
if (env->me_txns == MAP_FAILED) {
|
if (m == MAP_FAILED) {
|
||||||
rc = ErrCode();
|
env->me_txns = NULL;
|
||||||
goto fail;
|
rc = ErrCode();
|
||||||
}
|
goto fail;
|
||||||
|
}
|
||||||
|
env->me_txns = m;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
if (*excl) {
|
if (*excl) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
char hexbuf[17];
|
char hexbuf[17];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue