[ 
https://issues.apache.org/jira/browse/THRIFT-4624?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16601187#comment-16601187
 ] 

ASF GitHub Bot commented on THRIFT-4624:
----------------------------------------

jeking3 commented on a change in pull request #1585: THRIFT-4624: Fix refc 
binary leak
URL: https://github.com/apache/thrift/pull/1585#discussion_r214537979
 
 

 ##########
 File path: lib/erl/src/thrift_compact_protocol.erl
 ##########
 @@ -363,26 +365,32 @@ read(This0, double) ->
 % returns a binary directly, call binary_to_list if necessary
 read(This0, string) ->
   {This1, {ok, Sz}}  = read(This0, ui32),
-  read_data(This1, Sz).
+  read_data(This1, Sz, This0#t_compact.clone_binaries).
 
--spec read_data(#t_compact{}, non_neg_integer()) ->
+-spec read_data(#t_compact{}, non_neg_integer(), boolean()) ->
     {#t_compact{}, {ok, binary()} | {error, _Reason}}.
-read_data(This, 0) -> {This, {ok, <<>>}};
-read_data(This = #t_compact{transport = Trans}, Len) when is_integer(Len) 
andalso Len > 0 ->
-    {NewTransport, Result} = thrift_transport:read(Trans, Len),
+read_data(This, 0, _) -> {This, {ok, <<>>}};
+read_data(This, Len, Clone) when is_integer(Len) andalso Len > 0 ->
+    #t_compact{transport = Trans} = This,
+    {NewTransport, Result0} = thrift_transport:read(Trans, Len),
+    Result = case Result0 of
+                 {ok, Bin} when is_binary(Bin), Clone, Len > 64 ->
 
 Review comment:
   It sounded like you wanted to make one more change based on your original 
comment?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Refc binary leak in binary and compact protocols
> ------------------------------------------------
>
>                 Key: THRIFT-4624
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4624
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Erlang - Library
>            Reporter: something
>            Priority: Major
>
> Pattern-matching on large (>64B) Erlang binaries merely produces slices of 
> objects on the Refc heap. Therefore Thrift binary and compact protocols 
> should clone all binaries they send to upper levels, otherwise there's a 
> chance that transport-level messages will be never freed.
> Patch is underway.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to