revert the RW lock before throwing an exception

This commit is contained in:
Krasimir Angelov
2026-09-01 14:44:51 +02:00
parent f2e1b999b4
commit bda63328f7
+18 -6
View File
@@ -1839,32 +1839,44 @@ void PgfDB::resize_map(size_t new_size, bool writeable)
// OSX does not implement mremap or MREMAP_MAYMOVE // OSX does not implement mremap or MREMAP_MAYMOVE
#ifndef MREMAP_MAYMOVE #ifndef MREMAP_MAYMOVE
if (fd >= 0) { if (fd >= 0) {
if (munmap(base, mmap_size) == -1) if (munmap(base, mmap_size) == -1) {
pthread_rwlock_unlock(&ms->rwlock);
throw pgf_systemerror(errno); throw pgf_systemerror(errno);
}
base = NULL; base = NULL;
if (ms->file_size != new_size) { if (ms->file_size != new_size) {
if (ftruncate(fd, page_size+new_size) < 0) if (ftruncate(fd, page_size+new_size) < 0) {
pthread_rwlock_unlock(&ms->rwlock);
throw pgf_systemerror(errno, filepath); throw pgf_systemerror(errno, filepath);
}
} }
int prot = writeable ? PROT_READ | PROT_WRITE : PROT_READ; int prot = writeable ? PROT_READ | PROT_WRITE : PROT_READ;
new_base = new_base =
(unsigned char *) mmap(0, new_size, prot, MAP_SHARED, fd, page_size); (unsigned char *) mmap(0, new_size, prot, MAP_SHARED, fd, page_size);
if (new_base == MAP_FAILED) if (new_base == MAP_FAILED) {
pthread_rwlock_unlock(&ms->rwlock);
throw pgf_systemerror(errno); throw pgf_systemerror(errno);
}
} else { } else {
new_base = (unsigned char *) ::realloc(base, new_size); new_base = (unsigned char *) ::realloc(base, new_size);
if (new_base == NULL) if (new_base == NULL) {
pthread_rwlock_unlock(&ms->rwlock);
throw pgf_systemerror(ENOMEM); throw pgf_systemerror(ENOMEM);
}
} }
#else #else
if (fd >= 0 && ms->file_size != new_size) { if (fd >= 0 && ms->file_size != new_size) {
if (ftruncate(fd, page_size+new_size) < 0) if (ftruncate(fd, page_size+new_size) < 0) {
pthread_rwlock_unlock(&ms->rwlock);
throw pgf_systemerror(errno, filepath); throw pgf_systemerror(errno, filepath);
}
} }
new_base = new_base =
(unsigned char *) mremap(base, mmap_size, new_size, MREMAP_MAYMOVE); (unsigned char *) mremap(base, mmap_size, new_size, MREMAP_MAYMOVE);
if (new_base == MAP_FAILED) if (new_base == MAP_FAILED) {
pthread_rwlock_unlock(&ms->rwlock);
throw pgf_systemerror(errno); throw pgf_systemerror(errno);
}
#endif #endif
base = new_base; base = new_base;