Skip to content

Commit 1aa1a7c

Browse files
ayurchensysprg
authored andcommitted
MDEV-31809 Use MariaDB allocator where possible in wsrep_utils.cc
Signed-off-by: Julius Goryavsky <julius.goryavsky@mariadb.com>
1 parent d9f910b commit 1aa1a7c

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

sql/wsrep_utils.cc

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
#include <ifaddrs.h>
4444
#endif /* HAVE_GETIFADDRS */
4545

46+
#define MY_MALLOC(arg) my_malloc(key_memory_WSREP, arg, MYF(0))
47+
#define MY_REALLOC(p, arg) my_realloc(key_memory_WSREP, p, arg, MYF(MY_ALLOW_ZERO_PTR))
48+
#define MY_STRDUP(arg) my_strdup(key_memory_WSREP, arg, MYF(0))
49+
#define MY_FREE(arg) my_free(arg)
50+
4651
extern char** environ; // environment variables
4752

4853
static wsp::string wsrep_PATH;
@@ -96,16 +101,14 @@ namespace wsp
96101
bool
97102
env::ctor_common(char** e)
98103
{
99-
env_= static_cast<char**>(my_malloc(key_memory_WSREP,
100-
(len_ + 1) * sizeof(char*),
101-
0));
104+
env_= static_cast<char**>(MY_MALLOC((len_ + 1) * sizeof(char*)));
102105

103106
if (env_)
104107
{
105108
for (size_t i(0); i < len_; ++i)
106109
{
107110
assert(e[i]); // caller should make sure about len_
108-
env_[i]= my_strdup(key_memory_WSREP, e[i], MYF(0));
111+
env_[i]= MY_STRDUP(e[i]);
109112
if (!env_[i])
110113
{
111114
errno_= errno;
@@ -131,8 +134,8 @@ env::dtor()
131134
if (env_)
132135
{
133136
/* don't need to go beyond the first NULL */
134-
for (size_t i(0); env_[i] != NULL; ++i) { my_free(env_[i]); }
135-
my_free(env_);
137+
for (size_t i(0); env_[i] != NULL; ++i) { MY_FREE(env_[i]); }
138+
MY_FREE(env_);
136139
env_= NULL;
137140
}
138141
len_= 0;
@@ -159,13 +162,12 @@ env::~env() { dtor(); }
159162
int
160163
env::append(const char* val)
161164
{
162-
char** tmp= static_cast<char**>(my_realloc(key_memory_WSREP,
163-
env_, (len_ + 2)*sizeof(char*),
164-
0));
165+
char** tmp= static_cast<char**>(MY_REALLOC(env_, (len_ + 2)*sizeof(char*)));
166+
165167
if (tmp)
166168
{
167169
env_= tmp;
168-
env_[len_]= my_strdup(key_memory_WSREP, val, 0);
170+
env_[len_]= MY_STRDUP(val);
169171

170172
if (env_[len_])
171173
{
@@ -179,7 +181,6 @@ env::append(const char* val)
179181
return errno_;
180182
}
181183

182-
183184
#define READ_END 0
184185
#define WRITE_END 1
185186
#define STDIN_FD 0
@@ -267,7 +268,7 @@ process::close_io(io_direction const direction, bool const warn)
267268

268269
process::process (const char* cmd, const char* type, char** env)
269270
:
270-
str_(cmd ? strdup(cmd) : strdup("")),
271+
str_(cmd ? MY_STRDUP(cmd) : MY_STRDUP("")),
271272
io_{ NULL, NULL },
272273
err_(EINVAL),
273274
pid_(0)
@@ -300,7 +301,7 @@ process::process (const char* cmd, const char* type, char** env)
300301
int read_pipe[2]= { -1, -1 };
301302
int write_pipe[2]= { -1, -1 };
302303

303-
char* const pargv[4]= { strdup("sh"), strdup("-c"), strdup(str_), NULL };
304+
char* const pargv[4]= { MY_STRDUP("sh"), MY_STRDUP("-c"), MY_STRDUP(str_), NULL };
304305
if (!(pargv[0] && pargv[1] && pargv[2]))
305306
{
306307
err_= ENOMEM;
@@ -434,17 +435,17 @@ process::process (const char* cmd, const char* type, char** env)
434435
if (write_pipe[1] >= 0) close (write_pipe[1]);
435436

436437
cleanup_pargv:
437-
free (pargv[0]);
438-
free (pargv[1]);
439-
free (pargv[2]);
438+
MY_FREE(pargv[0]);
439+
MY_FREE(pargv[1]);
440+
MY_FREE(pargv[2]);
440441
}
441442

442443
process::~process ()
443444
{
444445
close_io(READ, true);
445446
close_io(WRITE, true);
446447

447-
if (str_) free (const_cast<char*>(str_));
448+
if (str_) MY_FREE(const_cast<char*>(str_));
448449
}
449450

450451
int

0 commit comments

Comments
 (0)