Skip to content

Commit

Permalink
Merge pull request #507 from MoarVM/decode-stream-leaks
Browse files Browse the repository at this point in the history
Fix decode stream leaks
  • Loading branch information
jnthn committed Jan 20, 2017
2 parents 870eeec + e8b3169 commit c68b326
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 15 deletions.
3 changes: 3 additions & 0 deletions src/6model/reprs/Decoder.c
Expand Up @@ -28,6 +28,9 @@ static void gc_mark(MVMThreadContext *tc, MVMSTable *st, void *data, MVMGCWorkli

/* Called by the VM in order to free memory associated with this object. */
static void gc_free(MVMThreadContext *tc, MVMObject *obj) {
MVMDecoder *decoder = (MVMDecoder *)obj;
if (decoder->body.ds)
MVM_string_decodestream_destroy(tc, decoder->body.ds);
}

static const MVMStorageSpec storage_spec = {
Expand Down
4 changes: 2 additions & 2 deletions src/io/asyncsocket.c
Expand Up @@ -149,7 +149,7 @@ static void read_gc_free(MVMThreadContext *tc, MVMObject *t, void *data) {
if (data) {
ReadInfo *ri = (ReadInfo *)data;
if (ri->ds)
MVM_string_decodestream_destory(tc, ri->ds);
MVM_string_decodestream_destroy(tc, ri->ds);
MVM_free(data);
}
}
Expand Down Expand Up @@ -491,7 +491,7 @@ static MVMint64 close_socket(MVMThreadContext *tc, MVMOSHandle *h) {
static void gc_free(MVMThreadContext *tc, MVMObject *h, void *d) {
MVMIOAsyncSocketData *data = (MVMIOAsyncSocketData *)d;
if (data->ds) {
MVM_string_decodestream_destory(tc, data->ds);
MVM_string_decodestream_destroy(tc, data->ds);
data->ds = NULL;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/io/asyncsocketudp.c
Expand Up @@ -152,7 +152,7 @@ static void read_gc_free(MVMThreadContext *tc, MVMObject *t, void *data) {
if (data) {
ReadInfo *ri = (ReadInfo *)data;
if (ri->ds)
MVM_string_decodestream_destory(tc, ri->ds);
MVM_string_decodestream_destroy(tc, ri->ds);
MVM_free(data);
}
}
Expand Down Expand Up @@ -511,7 +511,7 @@ static MVMint64 close_socket(MVMThreadContext *tc, MVMOSHandle *h) {
static void gc_free(MVMThreadContext *tc, MVMObject *h, void *d) {
MVMIOAsyncUDPSocketData *data = (MVMIOAsyncUDPSocketData *)d;
if (data->ds) {
MVM_string_decodestream_destory(tc, data->ds);
MVM_string_decodestream_destroy(tc, data->ds);
data->ds = NULL;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/io/procops.c
Expand Up @@ -1024,11 +1024,11 @@ static void spawn_gc_free(MVMThreadContext *tc, MVMObject *t, void *data) {
si->args = NULL;
}
if (si->ds_stdout) {
MVM_string_decodestream_destory(tc, si->ds_stdout);
MVM_string_decodestream_destroy(tc, si->ds_stdout);
si->ds_stdout = NULL;
}
if (si->ds_stderr) {
MVM_string_decodestream_destory(tc, si->ds_stderr);
MVM_string_decodestream_destroy(tc, si->ds_stderr);
si->ds_stderr = NULL;
}
MVM_free(si);
Expand Down
6 changes: 3 additions & 3 deletions src/io/syncfile.c
Expand Up @@ -46,7 +46,7 @@ static MVMint64 closefh(MVMThreadContext *tc, MVMOSHandle *h) {
MVMIOFileData *data = (MVMIOFileData *)h->body.data;
uv_fs_t req;
if (data->ds) {
MVM_string_decodestream_destory(tc, data->ds);
MVM_string_decodestream_destroy(tc, data->ds);
data->ds = NULL;
}
if (uv_fs_close(tc->loop, &req, data->fd, NULL) < 0) {
Expand Down Expand Up @@ -84,7 +84,7 @@ static void seek(MVMThreadContext *tc, MVMOSHandle *h, MVMint64 offset, MVMint64

if (data->ds) {
/* We'll start over from a new position. */
MVM_string_decodestream_destory(tc, data->ds);
MVM_string_decodestream_destroy(tc, data->ds);
data->ds = NULL;
}

Expand Down Expand Up @@ -403,7 +403,7 @@ static void gc_free(MVMThreadContext *tc, MVMObject *h, void *d) {
MVMIOFileData *data = (MVMIOFileData *)d;
if (data) {
if (data->ds)
MVM_string_decodestream_destory(tc, data->ds);
MVM_string_decodestream_destroy(tc, data->ds);
MVM_string_decode_stream_sep_destroy(tc, &(data->sep_spec));
if (data->filename)
MVM_free(data->filename);
Expand Down
2 changes: 1 addition & 1 deletion src/io/syncpipe.c
Expand Up @@ -42,7 +42,7 @@ static MVMint64 do_close(MVMThreadContext *tc, MVMIOSyncPipeData *data) {
data->process = NULL;
data->ss.handle = NULL;
if (data->ss.ds) {
MVM_string_decodestream_destory(tc, data->ss.ds);
MVM_string_decodestream_destroy(tc, data->ss.ds);
data->ss.ds = NULL;
}
return (MVMint64)status;
Expand Down
2 changes: 1 addition & 1 deletion src/io/syncsocket.c
Expand Up @@ -25,7 +25,7 @@ static MVMint64 do_close(MVMThreadContext *tc, MVMIOSyncSocketData *data) {
data->ss.handle = NULL;
}
if (data->ss.ds) {
MVM_string_decodestream_destory(tc, data->ss.ds);
MVM_string_decodestream_destroy(tc, data->ss.ds);
data->ss.ds = NULL;
}
return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/io/syncstream.c
Expand Up @@ -252,7 +252,7 @@ static MVMint64 closefh(MVMThreadContext *tc, MVMOSHandle *h) {
uv_close((uv_handle_t *)data->handle, NULL);
data->handle = NULL;
if (data->ds) {
MVM_string_decodestream_destory(tc, data->ds);
MVM_string_decodestream_destroy(tc, data->ds);
data->ds = NULL;
}
}
Expand Down Expand Up @@ -292,7 +292,7 @@ static void gc_free(MVMThreadContext *tc, MVMObject *h, void *d) {
data->handle = NULL;
}
if (data->ds) {
MVM_string_decodestream_destory(tc, data->ds);
MVM_string_decodestream_destroy(tc, data->ds);
data->ds = NULL;
}
MVM_string_decode_stream_sep_destroy(tc, &(data->sep_spec));
Expand Down
9 changes: 8 additions & 1 deletion src/strings/decode_stream.c
Expand Up @@ -500,14 +500,21 @@ MVMint32 MVM_string_decodestream_is_empty(MVMThreadContext *tc, MVMDecodeStream

/* Destroys a decoding stream, freeing all associated memory (including the
* buffers). */
void MVM_string_decodestream_destory(MVMThreadContext *tc, MVMDecodeStream *ds) {
void MVM_string_decodestream_destroy(MVMThreadContext *tc, MVMDecodeStream *ds) {
MVMDecodeStreamBytes *cur_bytes = ds->bytes_head;
MVMDecodeStreamChars *cur_chars = ds->chars_head;
while (cur_bytes) {
MVMDecodeStreamBytes *next_bytes = cur_bytes->next;
MVM_free(cur_bytes->bytes);
MVM_free(cur_bytes);
cur_bytes = next_bytes;
}
while (cur_chars) {
MVMDecodeStreamChars *next_chars = cur_chars->next;
MVM_free(cur_chars->chars);
MVM_free(cur_chars);
cur_chars = next_chars;
}
MVM_unicode_normalizer_cleanup(tc, &(ds->norm));
MVM_free(ds->decoder_state);
MVM_free(ds);
Expand Down
2 changes: 1 addition & 1 deletion src/strings/decode_stream.h
Expand Up @@ -88,7 +88,7 @@ MVMint64 MVM_string_decodestream_bytes_available(MVMThreadContext *tc, const MVM
MVMint64 MVM_string_decodestream_bytes_to_buf(MVMThreadContext *tc, MVMDecodeStream *ds, char **buf, MVMint32 bytes);
MVMint64 MVM_string_decodestream_tell_bytes(MVMThreadContext *tc, const MVMDecodeStream *ds);
MVMint32 MVM_string_decodestream_is_empty(MVMThreadContext *tc, MVMDecodeStream *ds);
void MVM_string_decodestream_destory(MVMThreadContext *tc, MVMDecodeStream *ds);
void MVM_string_decodestream_destroy(MVMThreadContext *tc, MVMDecodeStream *ds);
void MVM_string_decode_stream_sep_default(MVMThreadContext *tc, MVMDecodeStreamSeparators *sep_spec);
void MVM_string_decode_stream_sep_from_strings(MVMThreadContext *tc, MVMDecodeStreamSeparators *sep_spec, MVMString **seps, MVMint32 num_seps);
MVMint32 MVM_string_decode_stream_sep_max_chars(MVMThreadContext *tc, MVMDecodeStreamSeparators *sep_spec);
Expand Down

0 comments on commit c68b326

Please sign in to comment.