aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/beam/external.c
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2013-06-17 11:40:36 +0200
committerSverker Eriksson <[email protected]>2013-06-17 11:40:36 +0200
commita568634652396b0657e089100047f127804c970d (patch)
treeb141fcfb3df260c37c0b07be2d8506748754d9ba /erts/emulator/beam/external.c
parentc7fed1781bec1fbc893931a4d732a38a55f9ceea (diff)
parent80f8aab61f33f3c71e955de4303309e59db1138f (diff)
downloadotp-a568634652396b0657e089100047f127804c970d.tar.gz
otp-a568634652396b0657e089100047f127804c970d.tar.bz2
otp-a568634652396b0657e089100047f127804c970d.zip
Merge branch 'sverk/term_to_binary-memleak' into maint
* sverk/term_to_binary-memleak: erts: Fix memory leak in term_to_binary/2 with compressed option
Diffstat (limited to 'erts/emulator/beam/external.c')
-rw-r--r--erts/emulator/beam/external.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/erts/emulator/beam/external.c b/erts/emulator/beam/external.c
index 45025ad631..249b1e0923 100644
--- a/erts/emulator/beam/external.c
+++ b/erts/emulator/beam/external.c
@@ -1662,6 +1662,9 @@ static Eterm erts_term_to_binary_int(Process* p, Eterm Term, int level, Uint fla
pb->flags = 0;
OH_OVERHEAD(&(MSO(p)), pb->size / sizeof(Eterm));
erts_refc_inc(&result_bin->refc, 1);
+ if (context_b && erts_refc_read(&context_b->refc,0) == 0) {
+ erts_bin_free(context_b);
+ }
return make_binary(pb);
}
/* Continue with compression... */
@@ -1736,6 +1739,9 @@ static Eterm erts_term_to_binary_int(Process* p, Eterm Term, int level, Uint fla
context->s.cc.result_bin = NULL;
context->alive = 0;
BUMP_REDS(p, (this_time * CONTEXT_REDS) / TERM_TO_BINARY_COMPRESS_CHUNK);
+ if (context_b && erts_refc_read(&context_b->refc,0) == 0) {
+ erts_bin_free(context_b);
+ }
return make_binary(pb);
}
default: /* Compression error, revert to uncompressed binary (still in
@@ -1758,6 +1764,9 @@ static Eterm erts_term_to_binary_int(Process* p, Eterm Term, int level, Uint fla
context->s.cc.destination_bin = NULL;
context->alive = 0;
BUMP_REDS(p, (this_time * CONTEXT_REDS) / TERM_TO_BINARY_COMPRESS_CHUNK);
+ if (context_b && erts_refc_read(&context_b->refc,0) == 0) {
+ erts_bin_free(context_b);
+ }
return make_binary(pb);
}
}