summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwangyunjian <wangyunjian@huawei.com>2020-03-06 22:28:16 +0800
committerJens Geyer <jensg@apache.org>2020-09-17 11:34:17 +0200
commitc77941c60da01f466827ff619d571055ff76351f (patch)
tree23775871b3ad030c0cdb430d3d6c6dd6d4051bbf
parent0d6a2d36ea02839313e63421fb1ba4a9de2604ea (diff)
downloadthrift-c77941c60da01f466827ff619d571055ff76351f.tar.gz
THRIFT-5134: Fix memory leak when the handler method return FALSE
Client: c_glib Patch: wangyunjian This closes #2049 Signed-off-by: wangyunjian <wangyunjian@huawei.com>
-rw-r--r--compiler/cpp/src/thrift/generate/t_c_glib_generator.cc83
1 files changed, 41 insertions, 42 deletions
diff --git a/compiler/cpp/src/thrift/generate/t_c_glib_generator.cc b/compiler/cpp/src/thrift/generate/t_c_glib_generator.cc
index 2a92183eb..8cb82c180 100644
--- a/compiler/cpp/src/thrift/generate/t_c_glib_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_c_glib_generator.cc
@@ -2371,48 +2371,6 @@ void t_c_glib_generator::generate_service_processor(t_service* tservice) {
}
f_service_ << "return_value, "
<< "NULL);" << endl;
-
- // Deallocate (or unref) return_value
- return_type = get_true_type(return_type);
- if (return_type->is_base_type()) {
- t_base_type* base_type = ((t_base_type*)return_type);
-
- if (base_type->get_base() == t_base_type::TYPE_STRING) {
- f_service_ << indent() << "if (return_value != NULL)" << endl;
- indent_up();
- if (base_type->is_binary()) {
- f_service_ << indent() << "g_byte_array_unref (return_value);" << endl;
- } else {
- f_service_ << indent() << "g_free (return_value);" << endl;
- }
- indent_down();
- }
- } else if (return_type->is_container()) {
- f_service_ << indent() << "if (return_value != NULL)" << endl;
- indent_up();
-
- if (return_type->is_list()) {
- t_type* elem_type = ((t_list*)return_type)->get_elem_type();
-
- f_service_ << indent();
- if (is_numeric(elem_type)) {
- f_service_ << "g_array_unref";
- } else {
- f_service_ << "g_ptr_array_unref";
- }
- f_service_ << " (return_value);" << endl;
- } else if (return_type->is_map() || return_type->is_set()) {
- f_service_ << indent() << "g_hash_table_unref (return_value);" << endl;
- }
-
- indent_down();
- } else if (return_type->is_struct()) {
- f_service_ << indent() << "if (return_value != NULL)" << endl;
- indent_up();
- f_service_ << indent() << "g_object_unref (return_value);" << endl;
- indent_down();
- }
-
f_service_ << endl;
}
f_service_ << indent() << "result =" << endl;
@@ -2551,6 +2509,47 @@ void t_c_glib_generator::generate_service_processor(t_service* tservice) {
}
if (!(*function_iter)->is_oneway()) {
+ if (has_return_value) {
+ // Deallocate (or unref) return_value
+ return_type = get_true_type(return_type);
+ if (return_type->is_base_type()) {
+ t_base_type* base_type = ((t_base_type*)return_type);
+ if (base_type->get_base() == t_base_type::TYPE_STRING) {
+ f_service_ << indent() << "if (return_value != NULL)" << endl;
+ indent_up();
+ if (base_type->is_binary()) {
+ f_service_ << indent() << "g_byte_array_unref (return_value);" << endl;
+ } else {
+ f_service_ << indent() << "g_free (return_value);" << endl;
+ }
+ indent_down();
+ }
+ } else if (return_type->is_container()) {
+ f_service_ << indent() << "if (return_value != NULL)" << endl;
+ indent_up();
+
+ if (return_type->is_list()) {
+ t_type* elem_type = ((t_list*)return_type)->get_elem_type();
+
+ f_service_ << indent();
+ if (is_numeric(elem_type)) {
+ f_service_ << "g_array_unref";
+ } else {
+ f_service_ << "g_ptr_array_unref";
+ }
+ f_service_ << " (return_value);" << endl;
+ } else if (return_type->is_map() || return_type->is_set()) {
+ f_service_ << indent() << "g_hash_table_unref (return_value);" << endl;
+ }
+
+ indent_down();
+ } else if (return_type->is_struct()) {
+ f_service_ << indent() << "if (return_value != NULL)" << endl;
+ indent_up();
+ f_service_ << indent() << "g_object_unref (return_value);" << endl;
+ indent_down();
+ }
+ }
f_service_ << indent() << "g_object_unref (result_struct);" << endl << endl << indent()
<< "if (result == TRUE)" << endl;
indent_up();