Skip to content

Commit e0cfd2a

Browse files
committed
librepgp: store raw budget pointer in the dump limiter param
The limiting source param held a shared_ptr which was released via free() instead of its destructor, leaking one reference (and with it the whole shared budget allocation) per compressed packet - caught by LeakSanitizer on the CI sanitizer legs. The parent dump context owns the budget and always outlives the limiter, so a raw pointer suffices.
1 parent 7bc1c38 commit e0cfd2a

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

‎src/librepgp/stream-dump.cpp‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,9 @@ using namespace pgp;
581581
/* Source wrapper which limits the number of bytes which may be read through it,
582582
* used on top of the decompressed packet contents during the dump. */
583583
typedef struct dump_limited_src_param_t {
584-
pgp_source_t * readsrc;
585-
std::shared_ptr<dump_budget_t> budget;
584+
pgp_source_t *readsrc;
585+
/* owned by the parent dump context, which outlives this source */
586+
dump_budget_t *budget;
586587
} dump_limited_src_param_t;
587588

588589
static bool
@@ -611,9 +612,7 @@ dump_limited_src_close(pgp_source_t *src)
611612
}
612613

613614
static rnp_result_t
614-
init_dump_limited_src(pgp_source_t * src,
615-
pgp_source_t * readsrc,
616-
const std::shared_ptr<dump_budget_t> &budget)
615+
init_dump_limited_src(pgp_source_t *src, pgp_source_t *readsrc, dump_budget_t *budget)
617616
{
618617
if (!init_src_common(src, sizeof(dump_limited_src_param_t))) {
619618
return RNP_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
@@ -1494,7 +1493,7 @@ DumpContextDst::dump_compressed()
14941493
return ret;
14951494
}
14961495
Source lsrc;
1497-
if ((ret = init_dump_limited_src(&lsrc.src(), &zsrc->src(), zbudget))) {
1496+
if ((ret = init_dump_limited_src(&lsrc.src(), &zsrc->src(), zbudget.get()))) {
14981497
return ret;
14991498
}
15001499

@@ -2601,7 +2600,7 @@ DumpContextJson::dump_compressed(nlohmann::ordered_json &pkt)
26012600
return ret;
26022601
}
26032602
Source lsrc;
2604-
if ((ret = init_dump_limited_src(&lsrc.src(), &zsrc->src(), zbudget))) {
2603+
if ((ret = init_dump_limited_src(&lsrc.src(), &zsrc->src(), zbudget.get()))) {
26052604
return ret;
26062605
}
26072606

0 commit comments

Comments
 (0)