Details
-
Task
-
Status: Closed (View Workflow)
-
Critical
-
Resolution: Fixed
-
None
Description
The class Query_arena has a number of methods allocating data on Query_arena::mem_root:
inline void* alloc(size_t size) const { return alloc_root(mem_root,size); } |
inline void* calloc(size_t size) const |
{
|
void *ptr; |
if (likely((ptr=alloc_root(mem_root,size)))) |
bzero(ptr, size);
|
return ptr; |
}
|
inline char *strdup(const char *str) const |
{ return strdup_root(mem_root,str); } |
inline char *strmake(const char *str, size_t size) const |
{ return strmake_root(mem_root,str,size); } |
inline LEX_CSTRING strcat(const LEX_CSTRING &a, const LEX_CSTRING &b) const |
{
|
char *buf= (char*)alloc(a.length + b.length + 1); |
if (unlikely(!buf)) |
return null_clex_str; |
memcpy(buf, a.str, a.length); |
memcpy(buf + a.length, b.str, b.length); |
buf[a.length + b.length] = 0;
|
return {buf, a.length + b.length}; |
}
|
inline void *memdup(const void *str, size_t size) const |
{ return memdup_root(mem_root,str,size); } |
inline void *memdup_w_gap(const void *str, size_t size, size_t gap) const |
{
|
void *ptr; |
if (likely((ptr= alloc_root(mem_root,size+gap)))) |
memcpy(ptr,str,size); |
return ptr; |
}
|
Additionally, {{class THD} has more methods allocating data on Query_arena::mem_root:
LEX_CSTRING strmake_lex_cstring(const char *str, size_t length) const |
{
|
const char *tmp= strmake_root(mem_root, str, length); |
if (!tmp) |
return {0,0}; |
return {tmp, length}; |
}
|
LEX_CSTRING strmake_lex_cstring(const LEX_CSTRING &from) const |
{
|
return strmake_lex_cstring(from.str, from.length); |
}
|
 |
LEX_STRING *make_lex_string(LEX_STRING *lex_str, const char* str, |
size_t length) const |
{
|
if (!(lex_str->str= strmake_root(mem_root, str, length))) |
{
|
lex_str->length= 0;
|
return 0; |
}
|
lex_str->length= length;
|
return lex_str; |
}
|
LEX_CSTRING *make_lex_string(LEX_CSTRING *lex_str, const char* str, |
size_t length) const |
{
|
if (!(lex_str->str= strmake_root(mem_root, str, length))) |
{
|
lex_str->length= 0;
|
return 0; |
}
|
lex_str->length= length;
|
return lex_str; |
}
|
};
|
These methods use nothing of THD except Query_arena::mem_root.
Obviously, these methods are in a wrong place. Let's move them to Query_arena, so all MEM_ROOT allocating methods reside in the same place.
Note, MDEV-31606 will add some more MEM_ROOT allocating methods to Query_arena. It's better to collect all allocating methods into one place.
Attachments
Issue Links
- blocks
-
MDEV-31606 Refactor check_db_name() to get a const argument
- Closed