diff options
author | Jay Berkenbilt <ejb@ql.org> | 2019-06-22 20:24:49 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2019-06-22 22:57:52 +0200 |
commit | 6c39aa87638f7a6f96a97627ac112fb2022bd3a7 (patch) | |
tree | 6941498e1cacbd6dcade4a695b27085fa693984f /libqpdf/QPDFWriter.cc | |
parent | 12400475283f5081ea55f52a764e43f14032f6ba (diff) | |
download | qpdf-6c39aa87638f7a6f96a97627ac112fb2022bd3a7.tar.zst |
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.
Diffstat (limited to 'libqpdf/QPDFWriter.cc')
-rw-r--r-- | libqpdf/QPDFWriter.cc | 8 |
1 files changed, 4 insertions, 4 deletions
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<Buffer> buf = bufpl.getBuffer(); val = QPDF_String( std::string(reinterpret_cast<char*>(buf->getBuffer()), buf->getSize())).unparse(true); - delete buf; } else { - char* tmp = QUtil::copy_string(val); + PointerHolder<char> tmp_ph = + PointerHolder<char>(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 |