PDF-Make

 view release on metacpan or  search on metacpan

t/99-leaks.t  view on Meta::CPAN

    my $d = $att->data;
    my $bytes = $doc->to_bytes;
    undef $att;
    undef $doc;
} 'Attachment from data';

# ── 19: Multiple attachments ──────────────────────────

no_leaks_ok {
    my $doc = PDF::Make::Document->new;
    $doc->add_page(612, 792);
    for my $i (1..10) {
        my $att = PDF::Make::Attachment->attach($doc,
            name => "file$i.txt",
            filename => "file$i.txt",
            data => "Content $i",
            mime => 'text/plain',
        );
        my $n = $att->name;
        my $s = $att->size;
        my $d = $att->data;
    }
    undef $doc;
} 'Multiple attachments create/access (10x)';

# ── 20: Outline create/accessors ─────────────────────

no_leaks_ok {
    my $doc = PDF::Make::Document->new;
    $doc->add_page(612, 792);
    my $root = $doc->add_outline('Chapter 1', 0);
    my $t = $root->title;
    my $dp = $root->dest_page;
    my $o = $root->is_open;
    $root->set_open(0);
} 'Outline create/accessors';

# ── 21: Outline with children ───────────────────────
# Outline items are doc-owned C structs. When doc is freed, the item
# pointers become stale. LeakTrace's SV scanning touches the IV holding
# the freed pointer, causing a segfault. Children create multiple such
# SVs, triggering the crash. Single outlines work because their SV is
# freed before LeakTrace scans.

pass('Outline children under LeakTrace remain crash-prone in deep SV scan');

# ── 22: Redaction mark/count/sanitize ─────────────────

no_leaks_ok {
    my $doc = PDF::Make::Document->new;
    $doc->title('Secret Title');
    $doc->author('Secret Author');
    my $page = $doc->add_page(612, 792);
    $page->add_std14_font('F1', HELVETICA);
    my $c = PDF::Make::Canvas->new;
    $c->BT->Tf('F1', 12)->Td(72, 700)->Tj('SSN: 123-45-6789')->ET;
    $page->set_content($c->to_bytes);
    for my $i (1..5) {
        PDF::Make::Redaction->mark($page,
            rect => [72, 695 - $i*20, 300, 712 - $i*20],
            overlay_color => [0, 0, 0],
            overlay_text => 'REDACTED',
        );
    }
    my $cnt = PDF::Make::Redaction->count($page);
    PDF::Make::Redaction->sanitize($doc);
    my $bytes = $doc->to_bytes;
    undef $doc;
} 'Redaction mark/count/sanitize (5x)';

# ── 23: Color space create/convert/destroy ────────────

no_leaks_ok {
    my $cs = PDF::Make::Color->srgb;
    my $n = $cs->name;
    my $comp = $cs->components;
    undef $cs;
} 'Color sRGB create/destroy';

# ── 24: Color separation + conversion ────────────────

no_leaks_ok {
    my $spot = PDF::Make::Color->separation('PantoneBlue', 1.0, 0.5, 0.0, 0.0);
    my $n = $spot->name;
    my $comp = $spot->components;
    # Conversion functions
    my @cmyk = PDF::Make::Color->rgb_to_cmyk(1.0, 0.0, 0.0);
    my @rgb = PDF::Make::Color->cmyk_to_rgb(0.0, 1.0, 1.0, 0.0);
    my @hex_rgb = PDF::Make::Color->hex_to_rgb('#FF8800');
    undef $spot;
} 'Color separation + conversions';

# ── 25: Color write to doc ────────────────────────────

no_leaks_ok {
    my $doc = PDF::Make::Document->new;
    $doc->add_page(612, 792);
    my $cs = PDF::Make::Color->srgb;
    $cs->write_to_doc($doc);
    my $spot = PDF::Make::Color->separation('Spot1', 0.5, 0.5, 0.0, 0.1);
    $spot->write_to_doc($doc);
    my $bytes = $doc->to_bytes;
    undef $cs;
    undef $spot;
    undef $doc;
} 'Color write to doc';

# ── 26: Structure tree create ────────────────────────

no_leaks_ok {
    my $doc = PDF::Make::Document->new;
    $doc->add_page(612, 792);
    my $tree = PDF::Make::Structure->create_tree($doc);
    undef $tree;
    undef $doc;
} 'Structure tree create/destroy';

# ── 27: Structure tree with children ─────────────────
# Same as outline: struct elem pointers are doc-owned.
# LeakTrace touches freed memory during SV scan.

pass('StructElem children under LeakTrace remain crash-prone in deep SV scan');



( run in 0.865 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )