thrift-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Zezeng Wang (Jira)" <j...@apache.org>
Subject [jira] [Created] (THRIFT-5222) Manage memory with smart pointer
Date Sat, 30 May 2020 04:12:00 GMT
Zezeng Wang created THRIFT-5222:
-----------------------------------

             Summary: Manage memory with smart pointer
                 Key: THRIFT-5222
                 URL: https://issues.apache.org/jira/browse/THRIFT-5222
             Project: Thrift
          Issue Type: Improvement
          Components: C++ - Compiler, Compiler (General)
            Reporter: Zezeng Wang


Thrift current allocate memory is still exist traditional manual new manual delete in most
of the code´╝îit will┬áincrease the probability of memory leak.

Since thrift already adopt c++11, maybe use smart pointer is a better solution.
{code:cpp}
void initGlobals() {
  g_type_void = new t_base_type("void", t_base_type::TYPE_VOID);
  g_type_string = new t_base_type("string", t_base_type::TYPE_STRING);
  g_type_binary = new t_base_type("string", t_base_type::TYPE_STRING);
  ((t_base_type*)g_type_binary)->set_binary(true);
  g_type_slist = new t_base_type("string", t_base_type::TYPE_STRING);
  ((t_base_type*)g_type_slist)->set_string_list(true);
  g_type_bool = new t_base_type("bool", t_base_type::TYPE_BOOL);
  g_type_i8 = new t_base_type("i8", t_base_type::TYPE_I8);
  g_type_i16 = new t_base_type("i16", t_base_type::TYPE_I16);
  g_type_i32 = new t_base_type("i32", t_base_type::TYPE_I32);
  g_type_i64 = new t_base_type("i64", t_base_type::TYPE_I64);
  g_type_double = new t_base_type("double", t_base_type::TYPE_DOUBLE);
}

void clearGlobals() {
  delete g_type_void;
  delete g_type_string;
  delete g_type_bool;
  delete g_type_i8;
  delete g_type_i16;
  delete g_type_i32;
  delete g_type_i64;
  delete g_type_double;
}
{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Mime
View raw message