> Moving the `delete[] row;` should avoid requiring two identical lines: > > delete[] row; > + if (!writer->close()) { > + return splashErrGeneric; > + } Yes, but libjpeg keeps a reference to row and may access it during jpeg_finish_compress(). So deleting row before writer->close() is a Bad Idea.