Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions devel/0178.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# [0178] 修复 pdf_hummus_renderer 中 DestinationsWriter 的内存泄漏

## 相关文档
- [0171.md](0171.md) - 上一轮内存泄漏修复

## 任务相关的代码文件
- `src/Plugins/Pdf/pdf_hummus_renderer.cpp`

## 如何测试

### 确定性测试
```bash
xmake b stem
```

## What

1. 修复 `pdf_hummus_renderer_rep` 构造函数中 `DestinationsWriter` 的内存泄漏。构造函数通过 `new DestinationsWriter(this)` 创建对象并传给 `AddDocumentContextExtender`,但 PDFHummus 的 `DocumentContext` 只存储裸指针,不会负责释放。析构函数中也从未释放该对象。

## Why

每次创建 PDF 导出渲染器都会泄漏一个 `DestinationsWriter` 对象。PDFHummus 的 `mExtenders.clear()` 只清除指针列表,不释放对象。

## How

将 `DestinationsWriter*` 存储为 `pdf_hummus_renderer_rep` 的成员变量,在析构函数中 `delete`。
11 changes: 8 additions & 3 deletions src/Plugins/Pdf/pdf_hummus_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ class pdf_hummus_renderer_rep : public renderer_rep {
}
};

DestinationsWriter* destinations_writer;

PDFHummus::EStatusCode
on_catalog_write (CatalogInformation* inCatalogInformation,
DictionaryContext* inCatalogDictionaryContext,
Expand Down Expand Up @@ -310,7 +312,7 @@ pdf_hummus_renderer_rep::pdf_hummus_renderer_rep (
paper_w (paper_w2), paper_h (paper_h2), page_num (0), inText (false),
fg (-1), bg (-1), lw (-1), pen (black), bgb (white), fgb (black),
cfn (""), cfid (NULL), native_fonts (NULL), t3font_registry_id (-1),
destId (0), label_count (0), outlineId (0) {
destId (0), label_count (0), outlineId (0), destinations_writer (NULL) {
width = default_dpi * paper_w / 2.54;
height= default_dpi * paper_h / 2.54;

Expand All @@ -334,9 +336,10 @@ pdf_hummus_renderer_rep::pdf_hummus_renderer_rep (
started= false;
}
else {
started= true;
started = true;
destinations_writer= new DestinationsWriter (this);
pdfWriter.GetDocumentContext ().AddDocumentContextExtender (
new DestinationsWriter (this));
destinations_writer);

// create a graphic state with default values
initial_GState_id= pdfWriter.GetObjectsContext ()
Expand Down Expand Up @@ -420,6 +423,8 @@ pdf_hummus_renderer_rep::~pdf_hummus_renderer_rep () {
convert_error << "Failed in end PDF\n";
}

delete destinations_writer;

// remove temporary pictures
for (int i= 0; i < N (temp_images); i++)
if (!is_none (temp_images[i]) && exists (temp_images[i]))
Expand Down
Loading