From 6c39aa87638f7a6f96a97627ac112fb2022bd3a7 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 22 Jun 2019 14:24:49 -0400 Subject: In shippable code, favor smart pointers (fixes #235) Use PointerHolder in several places where manually memory allocation and deallocation were being used. This helps to protect against memory leaks when exceptions are thrown in surprising places. --- libqpdf/QPDFWriter.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libqpdf/QPDFWriter.cc') diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc index 7702dc34..41d5ab30 100644 --- a/libqpdf/QPDFWriter.cc +++ b/libqpdf/QPDFWriter.cc @@ -1835,21 +1835,21 @@ QPDFWriter::unparseObject(QPDFObjectHandle object, int level, this->m->cur_data_key.length()); pl.write(QUtil::unsigned_char_pointer(val), val.length()); pl.finish(); - Buffer* buf = bufpl.getBuffer(); + PointerHolder buf = bufpl.getBuffer(); val = QPDF_String( std::string(reinterpret_cast(buf->getBuffer()), buf->getSize())).unparse(true); - delete buf; } else { - char* tmp = QUtil::copy_string(val); + PointerHolder tmp_ph = + PointerHolder(true, QUtil::copy_string(val)); + char* tmp = tmp_ph.getPointer(); size_t vlen = val.length(); RC4 rc4(QUtil::unsigned_char_pointer(this->m->cur_data_key), QIntC::to_int(this->m->cur_data_key.length())); rc4.process(QUtil::unsigned_char_pointer(tmp), vlen); val = QPDF_String(std::string(tmp, vlen)).unparse(); - delete [] tmp; } } else -- cgit v1.2.3-54-g00ecf