You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Zezeng Wang (Jira)" <ji...@apache.org> on 2020/05/30 06:12:00 UTC
[jira] [Updated] (THRIFT-5222) Manage memory with smart pointer
[ https://issues.apache.org/jira/browse/THRIFT-5222?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Zezeng Wang updated THRIFT-5222:
--------------------------------
Description:
Thrift's 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}
was:
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}
> 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
> Priority: Major
>
> Thrift's 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)