From c9b055fa03a7ca849b1f8301061119323bfe61fb Mon Sep 17 00:00:00 2001 From: Evgeny Pokhilko Date: Thu, 8 Feb 2018 00:43:20 +1100 Subject: [PATCH] Fix: memory leak in PacketReader / Writer The leak occurred because of missing virtual destructors --- deps/libencryptmsg/src/packet_reader.h | 5 +++++ deps/libencryptmsg/src/packet_writer.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/deps/libencryptmsg/src/packet_reader.h b/deps/libencryptmsg/src/packet_reader.h index fcdc489d..2341af2b 100644 --- a/deps/libencryptmsg/src/packet_reader.h +++ b/deps/libencryptmsg/src/packet_reader.h @@ -28,6 +28,11 @@ namespace LibEncryptMsg public: PacketRWBase(SessionState &state, bool is_final_packet) :state_(state), is_final_packet_(is_final_packet){} + + virtual ~PacketRWBase(){} + PacketRWBase(const PacketRWBase&) = delete; + PacketRWBase &operator=(const PacketRWBase&) = delete; + // Reads packet body and writes its payload while setting metadata_out fields // Payload is the contained packets or empty if there are no packets inside EmsgResult Read(OutStream &out) diff --git a/deps/libencryptmsg/src/packet_writer.h b/deps/libencryptmsg/src/packet_writer.h index c4852b59..1d0e7d36 100644 --- a/deps/libencryptmsg/src/packet_writer.h +++ b/deps/libencryptmsg/src/packet_writer.h @@ -21,6 +21,11 @@ namespace LibEncryptMsg void Write(OutStream &out); void Finish(OutStream &out); InBufferStream &GetInStream(); + + virtual ~PacketWriter(){} + PacketWriter(const PacketWriter&) = delete; + PacketWriter &operator=(const PacketWriter&) = delete; + protected: InBufferStream in_; InBufferStream out_;