[0178] 修复 mupdf 渲染器 register_pattern 的内存泄漏#3586
Open
da-liii wants to merge 4 commits into
Open
Conversation
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 新增 mupdf_renderer_test,通过 RSS 监控检测 register_pattern 的内存泄漏 - 修复 format_picsize_string 在无 GUI 环境下调用 get_current_editor 崩溃的问题, 使测试可在 headless 环境中运行 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1. 在 pdf_close_processor 后添加 pdf_drop_processor,释放 buffer processor 2. 在 pdf_dict_puts 后添加 pdf_drop_obj(ctx, xres),释放 xres 原始引用 3. 定义 mupdf_pattern_drop_imp 作为手动创建 pattern 的释放函数 4. 使用 FZ_INIT_STORABLE 初始化 pdf_pattern 的 storable.drop 5. 移除 register_pattern 中多余的 pdf_drop_pattern 调用, 让 mupdf_pattern 的引用计数管理接管生命周期 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 按照 dddd.md 模板重新组织文档结构 - 在如何测试部分补充普通用户可验证的场景: 创建带有 pattern brush 的文档并反复导出 PDF, 观察内存占用是否稳定 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
任务描述
基于 0177 的内存监控能力,采用 TDD 方式查找并修复 mupdf 渲染器中的内存泄漏问题。
改动内容
Commit 1: 任务文档
devel/0178.mdCommit 2: 复现内存泄漏的单元测试
tests/Plugins/MuPDF/mupdf_renderer_test.cppformat_picsize_string在无 GUI 环境下调用get_current_editor崩溃的问题,使测试可在 headless 环境中运行Commit 3: 修复内存泄漏
在
src/Plugins/MuPDF/mupdf_renderer.cpp的register_pattern中修复三处内存泄漏:pdf_new_buffer_processor创建的 processor 仅被pdf_close_processor关闭,未被pdf_drop_processor释放pdf_dict_puts(ctx, subres, "XObject", xres)后未调用pdf_drop_obj(ctx, xres)释放原始引用pdf_pattern使用fz_malloc_struct分配(清零),但未初始化storable.drop函数指针。pdf_drop_pattern在引用计数降至 0 时因drop为 NULL 而无法释放pat、resources和contents修复方案:
pdf_close_processor后添加pdf_drop_processorpdf_dict_puts后添加pdf_drop_obj(ctx, xres)mupdf_pattern_drop_imp作为手动创建 pattern 的释放函数,并使用FZ_INIT_STORABLE初始化patregister_pattern中多余的pdf_drop_pattern(ctx, pat)调用,让mupdf_pattern的引用计数管理接管生命周期测试验证
测试通过,RSS 增长稳定,内存泄漏已修复。
🤖 Generated with Claude Code