Tencent/matrix · error
Failed to create maps.txt
Error message
Failed to create maps.txt
What it means
SaveData() in unwind_for_offline writes the sorted /proc/<pid>/maps entries to 'maps.txt' with fopen("maps.txt","w+"). A null FILE* makes the tool print 'Failed to create maps.txt' (plus the errno detail from perror) and return false, so the offline unwind bundle cannot be produced. This is the first file the tool tries to create, so its failure usually blocks the whole capture.
Solutions
- Start the tool from a writable directory (e.g. /data/local/tmp or $HOME)
- Address the errno from perror: chmod/chown the directory or free disk space
- Delete/rename any blocking maps.txt directory or file
- Patch the tool to accept an output directory argument
Example fix
// before
fp(fopen("maps.txt", "w+"), &fclose);
// after
const char *out = getenv("UNWIND_OUT") ? getenv("UNWIND_OUT") : "maps.txt";
fp(fopen(out, "w+"), &fclose); Defensive patterns
Strategy: validation
Validate before calling
if (access(".", W_OK) != 0) { fprintf(stderr, "cwd not writable for maps.txt\n"); return 1; } Try / catch
FILE *fp = fopen("maps.txt", "w+");
if (!fp) { perror("Failed to create maps.txt"); fp = fopen("/data/local/tmp/maps.txt", "w+"); }
if (!fp) return false; Prevention
- Launch unwind_for_offline from a writable cwd (e.g. /data/local/tmp)
- Confirm SELinux allows file creation for the executing uid
- Check free space before running captures
- Use an output-dir flag/patch rather than relying on cwd
When it happens
Trigger: fopen("maps.txt") fails in the tool's working directory: read-only filesystem, permission denied, disk full, or name collision with an existing directory; called from main after reading process maps.
Common situations: Running the tool in adb shell from /system or another unwritable path, SELinux denials on device, or CI containers with read-only workdirs while collecting maps for offline symbolication.
Understand the failure class
Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.
Related errors
- Failed to create file regs.txt
- Failed to create stack.data
- Matrix init, Matrix should not be null.
- you must init Matrix sdk first
- matrix init, application is null
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/da7cbd9ae9e8ffd1.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/matrix-backtrace/src/main/cpp/external/libunwindstack/tools/unwind_for_offline.cpp:311
}
}
for (size_t i = 0; i < unwinder.NumFrames(); i++) {
printf("%s\n", unwinder.FormatFrame(i).c_str());
}
if (!SaveStack(pid, stacks)) {
return 1;
}
std::vector<std::pair<uint64_t, map_info_t>> sorted_maps(maps_by_start.begin(),
maps_by_start.end());
std::sort(sorted_maps.begin(), sorted_maps.end(),
[](auto& a, auto& b) { return a.first < b.first; });
std::unique_ptr<FILE, decltype(&fclose)> fp(fopen("maps.txt", "w+"), &fclose);
if (fp == nullptr) {
perror("Failed to create maps.txt");
return false;
}
for (auto& element : sorted_maps) {
char perms[5] = {"---p"};
map_info_t& map = element.second;
if (map.flags & PROT_READ) {
perms[0] = 'r';
}
if (map.flags & PROT_WRITE) {
perms[1] = 'w';
}
if (map.flags & PROT_EXEC) {
perms[2] = 'x';
}
fprintf(fp.get(), "%" PRIx64 "-%" PRIx64 " %s %" PRIx64 " 00:00 0", map.start, map.end, perms,
map.offset);
if (!map.name.empty()) {View on GitHub (pinned to 3b8293bd65)