Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

double-free when encoding. #125

Open
g199209 opened this issue Feb 14, 2023 · 1 comment
Open

double-free when encoding. #125

g199209 opened this issue Feb 14, 2023 · 1 comment

Comments

@g199209
Copy link

g199209 commented Feb 14, 2023

template file:

<?xml version="1.0" encoding="UTF-8"?>
<templates version="2.25" xmlns="http://www.fixprotocol.org/ns/template-definition"> 
  <template id="1" name="FirstMessage">
    <string id="1" name="ID" presence="optional"><copy/></string>
  </template>
	<template id="2" name="SecondMessage">
	  <string id="1" name="ID"><tail/></string>
	</template>
</templates>

There are two ID fields in two different message, the first one has copy attribute and another has tail attribute.

mFAST encoder will double free memory when encoding this template.

copy & tail attribute is the key point, the program will not crash when removing any of them.


I found a easy way to solve it :

diff --git a/src/mfast/coder/common/template_repo.h b/src/mfast/coder/common/template_repo.h
index d949d56..b0fa690 100644
--- a/src/mfast/coder/common/template_repo.h
+++ b/src/mfast/coder/common/template_repo.h
@@ -18,6 +18,8 @@ public:
       if (elem->of_array.capacity_in_bytes_)
         dictionary_alloc_->deallocate(elem->of_array.content_,
                                       elem->of_array.capacity_in_bytes_);
+        elem->of_array.content_ = nullptr;
+        elem->of_array.capacity_in_bytes_ = 0;
     }
   }

I think it's just a workaround not the root cause?

@adamyg
Copy link

adamyg commented Feb 16, 2023

same as #123; occurs during dict cleanup, shall review solution, thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants