cppcheck: memleakOnRealloc

Change-Id: Ibdf762b0d397f798372d9bf882aa82a6e5fd0229
This commit is contained in:
Caolán McNamara
2015-05-04 15:50:42 +01:00
parent 90911df79e
commit 24736e724e
2 changed files with 9 additions and 18 deletions

View File

@@ -21,27 +21,19 @@
#include <stdlib.h> #include <stdlib.h>
#include "hstream.hxx" #include "hstream.hxx"
HStream::HStream() : size(0), pos(0) HStream::HStream()
: size(0)
, pos(0)
{ {
seq = 0;
} }
void HStream::addData(const byte *buf, int aToAdd)
HStream::~HStream()
{ {
if( seq ) seq.resize(size + aToAdd);
free( seq ); memcpy(seq.data() + size, buf, aToAdd);
}
void HStream::addData( const byte *buf, int aToAdd)
{
seq = static_cast<byte *>(realloc( seq, size + aToAdd ));
memcpy( seq + size, buf, aToAdd );
size += aToAdd; size += aToAdd;
} }
int HStream::readBytes(byte * buf, int aToRead) int HStream::readBytes(byte * buf, int aToRead)
{ {
if (aToRead >= (size - pos)) if (aToRead >= (size - pos))
@@ -51,7 +43,6 @@ int HStream::readBytes(byte * buf, int aToRead)
return aToRead; return aToRead;
} }
int HStream::skipBytes(int aToSkip) int HStream::skipBytes(int aToSkip)
{ {
if (aToSkip >= (size - pos)) if (aToSkip >= (size - pos))
@@ -60,7 +51,6 @@ int HStream::skipBytes(int aToSkip)
return aToSkip; return aToSkip;
} }
int HStream::available() const int HStream::available() const
{ {
return size - pos; return size - pos;

View File

@@ -20,6 +20,8 @@
#ifndef INCLUDED_HWPFILTER_SOURCE_HSTREAM_H #ifndef INCLUDED_HWPFILTER_SOURCE_HSTREAM_H
#define INCLUDED_HWPFILTER_SOURCE_HSTREAM_H #define INCLUDED_HWPFILTER_SOURCE_HSTREAM_H
#include <vector>
typedef unsigned char byte; typedef unsigned char byte;
/** /**
* Stream class * Stream class
@@ -28,7 +30,6 @@ class HStream
{ {
public: public:
HStream(); HStream();
virtual ~HStream();
/** /**
* *
@@ -49,7 +50,7 @@ class HStream
private: private:
int size; int size;
byte *seq; std::vector<byte> seq;
int pos; int pos;
}; };
#endif #endif