From 24736e724e98a3ed63bad5e1917f40302b1de24e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Mon, 4 May 2015 15:50:42 +0100 Subject: [PATCH] cppcheck: memleakOnRealloc Change-Id: Ibdf762b0d397f798372d9bf882aa82a6e5fd0229 --- hwpfilter/source/hstream.cxx | 22 ++++++---------------- hwpfilter/source/hstream.hxx | 5 +++-- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/hwpfilter/source/hstream.cxx b/hwpfilter/source/hstream.cxx index c9bd0d3ca066..6a0d59f48048 100644 --- a/hwpfilter/source/hstream.cxx +++ b/hwpfilter/source/hstream.cxx @@ -21,27 +21,19 @@ #include #include "hstream.hxx" -HStream::HStream() : size(0), pos(0) +HStream::HStream() + : size(0) + , pos(0) { - seq = 0; } - -HStream::~HStream() +void HStream::addData(const byte *buf, int aToAdd) { - if( seq ) - free( seq ); -} - - -void HStream::addData( const byte *buf, int aToAdd) -{ - seq = static_cast(realloc( seq, size + aToAdd )); - memcpy( seq + size, buf, aToAdd ); + seq.resize(size + aToAdd); + memcpy(seq.data() + size, buf, aToAdd); size += aToAdd; } - int HStream::readBytes(byte * buf, int aToRead) { if (aToRead >= (size - pos)) @@ -51,7 +43,6 @@ int HStream::readBytes(byte * buf, int aToRead) return aToRead; } - int HStream::skipBytes(int aToSkip) { if (aToSkip >= (size - pos)) @@ -60,7 +51,6 @@ int HStream::skipBytes(int aToSkip) return aToSkip; } - int HStream::available() const { return size - pos; diff --git a/hwpfilter/source/hstream.hxx b/hwpfilter/source/hstream.hxx index 426d39650939..4374b92674e3 100644 --- a/hwpfilter/source/hstream.hxx +++ b/hwpfilter/source/hstream.hxx @@ -20,6 +20,8 @@ #ifndef INCLUDED_HWPFILTER_SOURCE_HSTREAM_H #define INCLUDED_HWPFILTER_SOURCE_HSTREAM_H +#include + typedef unsigned char byte; /** * Stream class @@ -28,7 +30,6 @@ class HStream { public: HStream(); - virtual ~HStream(); /** * @@ -49,7 +50,7 @@ class HStream private: int size; - byte *seq; + std::vector seq; int pos; }; #endif