if (fd == -1) {
data->mmap_full_length = INDEX_DATA_INITIAL_SIZE;
data->mmap_base = mmap_anon(data->mmap_full_length);
+ if (data->mmap_base == MAP_FAILED) {
+ i_free(data);
+ return index_file_set_syscall_error(index, path,
+ "mmap_anon()");
+ }
memcpy(data->mmap_base, &hdr, sizeof(hdr));
data->header = data->mmap_base;
index->mmap_full_length = INDEX_FILE_MIN_SIZE;
index->mmap_base = mmap_anon(index->mmap_full_length);
+ if (index->mmap_base == MAP_FAILED)
+ return index_file_set_syscall_error(index, path, "mmap_anon()");
mail_index_init_header(index, index->mmap_base);
index->header = index->mmap_base;
return FALSE;
}
-static void modifylog_create_anon(struct modify_log_file *file)
+static int modifylog_create_anon(struct modify_log_file *file)
{
file->mmap_full_length = MODIFY_LOG_INITIAL_SIZE;
file->mmap_base = mmap_anon(file->mmap_full_length);
file->header = file->mmap_base;
+ if (file->mmap_base == MAP_FAILED)
+ return modifylog_set_syscall_error(file, "mmap_anon()");
+
mail_modifylog_init_header(file->log, file->mmap_base);
file->mmap_used_length = file->header->used_file_size;
file->anon_mmap = TRUE;
file->filepath = i_strdup_printf("(in-memory modify log for %s)",
file->log->index->mailbox_path);
+ return TRUE;
}
int mail_modifylog_create(struct mail_index *index)
log = mail_modifylog_new(index);
- if (INDEX_IS_IN_MEMORY(index))
- modifylog_create_anon(&log->file1);
- else {
+ if (INDEX_IS_IN_MEMORY(index)) {
+ if (!modifylog_create_anon(&log->file1)) {
+ mail_modifylog_free(log);
+ return FALSE;
+ }
+ } else {
ret = modifylog_reuse_or_create_file(&log->file1);
if (ret == 0) {
index_set_error(log->index,
if (tree->anon_mmap) {
tree->mmap_full_length = MAIL_TREE_MIN_SIZE;
tree->mmap_base = mmap_anon(tree->mmap_full_length);
+ if (tree->mmap_base == MAP_FAILED)
+ return tree_set_syscall_error(tree, "mmap_anon()");
+
memcpy(tree->mmap_base, &hdr, sizeof(struct mail_tree_header));
return mmap_verify(tree);
}