fix memory serialize memory leak

This commit is contained in:
tqcq 2023-12-03 21:28:57 +08:00
parent 0618406a7d
commit 5e23c20364
2 changed files with 6 additions and 3 deletions

View File

@ -313,7 +313,6 @@ CMessagePlugin::GenerateFunctionDefinitionSerialize(Message::Ptr message)
ss << " if (status != 0) { break; }" << std::endl; ss << " if (status != 0) { break; }" << std::endl;
ss << " tpl_dump(tn, TPL_MEM, buffer, buffer_size);" << std::endl; ss << " tpl_dump(tn, TPL_MEM, buffer, buffer_size);" << std::endl;
ss << " tpl_free(tn);" << std::endl; ss << " tpl_free(tn);" << std::endl;
ss << " return *buffer_size; " << std::endl;
ss << " } while (0);" << std::endl; ss << " } while (0);" << std::endl;
for (int idx = 0; idx < message->items().size(); idx++) { for (int idx = 0; idx < message->items().size(); idx++) {
@ -323,7 +322,11 @@ CMessagePlugin::GenerateFunctionDefinitionSerialize(Message::Ptr message)
} }
} }
} }
ss << " return 0; " << std::endl; ss << " if (status) {" << std::endl;
ss << " return -1;" << std::endl;
ss << " } else {" << std::endl;
ss << " return *buffer_size;" << std::endl;
ss << " }" << std::endl;
ss << "}" << std::endl; ss << "}" << std::endl;
return ss.str(); return ss.str();
} }

View File

@ -101,7 +101,7 @@ CRPCServer::GenerateStructAPIWrapper(std::string service_id) const
ss << " status = 0;" << std::endl; ss << " status = 0;" << std::endl;
ss << " } while (0);" << std::endl; ss << " } while (0);" << std::endl;
ss << " free(buffer);" << std::endl; ss << " free(buffer);" << std::endl;
// ss << " free(base64_buffer);" << std::endl; ss << " free(base64_buffer);" << std::endl;
ss << " free(response_msg);" << std::endl; ss << " free(response_msg);" << std::endl;
ss << " " << response_id() << "_Destroy(&response);" << std::endl; ss << " " << response_id() << "_Destroy(&response);" << std::endl;
ss << " " << request_id() << "_Destroy(&request);" << std::endl; ss << " " << request_id() << "_Destroy(&request);" << std::endl;