aboutsummaryrefslogtreecommitdiffstats
path: root/src/DecoderBuffer.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-07 23:17:39 +0100
committerMax Kellermann <max@duempel.org>2014-01-07 23:31:26 +0100
commit49f34fbf6861f10dbf9eb7549177888394926ff9 (patch)
treec02194e5f5c73b6bb7447b29565f8e178dbd562b /src/DecoderBuffer.cxx
parentfe6094a8227c61e055a49fcfd8720b42c5276ac1 (diff)
downloadmpd-49f34fbf6861f10dbf9eb7549177888394926ff9.tar.gz
mpd-49f34fbf6861f10dbf9eb7549177888394926ff9.tar.xz
mpd-49f34fbf6861f10dbf9eb7549177888394926ff9.zip
DecoderBuffer: use NewVarSize()
Diffstat (limited to 'src/DecoderBuffer.cxx')
-rw-r--r--src/DecoderBuffer.cxx23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/DecoderBuffer.cxx b/src/DecoderBuffer.cxx
index bc65dd15d..0f592b020 100644
--- a/src/DecoderBuffer.cxx
+++ b/src/DecoderBuffer.cxx
@@ -21,8 +21,7 @@
#include "DecoderBuffer.hxx"
#include "DecoderAPI.hxx"
#include "util/ConstBuffer.hxx"
-
-#include <glib.h>
+#include "util/VarSize.hxx"
#include <assert.h>
#include <string.h>
@@ -43,24 +42,22 @@ struct DecoderBuffer {
/** the actual buffer (dynamic size) */
unsigned char data[sizeof(size_t)];
+
+ DecoderBuffer(Decoder *_decoder, InputStream &_is,
+ size_t _size)
+ :decoder(_decoder), is(&_is),
+ size(_size), length(0), consumed(0) {}
};
DecoderBuffer *
decoder_buffer_new(Decoder *decoder, InputStream &is,
size_t size)
{
- DecoderBuffer *buffer = (DecoderBuffer *)
- g_malloc(sizeof(*buffer) - sizeof(buffer->data) + size);
-
assert(size > 0);
- buffer->decoder = decoder;
- buffer->is = &is;
- buffer->size = size;
- buffer->length = 0;
- buffer->consumed = 0;
-
- return buffer;
+ return NewVarSize<DecoderBuffer>(sizeof(DecoderBuffer::data),
+ size,
+ decoder, is, size);
}
void
@@ -68,7 +65,7 @@ decoder_buffer_free(DecoderBuffer *buffer)
{
assert(buffer != nullptr);
- g_free(buffer);
+ DeleteVarSize(buffer);
}
bool