MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / my_realloc

Function my_realloc

mysys/my_malloc.c:80–126  ·  view source on GitHub ↗

@brief wrapper around realloc() @param oldpoint pointer to currently allocated area @param size new size requested, must be >0 @param my_flags flags @note if size==0 realloc() may return NULL; my_realloc() treats this as an error which is not the intention of realloc() */

Source from the content-addressed store, hash-verified

78 error which is not the intention of realloc()
79*/
80void *my_realloc(void *oldpoint, size_t size, myf my_flags)
81{
82 void *point;
83 DBUG_ENTER("my_realloc");
84 DBUG_PRINT("my",("ptr: %p size: %lu my_flags: %d", oldpoint,
85 (ulong) size, my_flags));
86
87 DBUG_ASSERT(size > 0);
88 /* These flags are mutually exclusive. */
89 DBUG_ASSERT(!((my_flags & MY_FREE_ON_ERROR) &&
90 (my_flags & MY_HOLD_ON_ERROR)));
91 DBUG_EXECUTE_IF("simulate_out_of_memory",
92 point= NULL;
93 goto end;);
94 if (!oldpoint && (my_flags & MY_ALLOW_ZERO_PTR))
95 DBUG_RETURN(my_malloc(size, my_flags));
96#ifdef USE_HALLOC
97 point= malloc(size);
98#else
99 point= realloc(oldpoint, size);
100#endif
101#ifndef DBUG_OFF
102end:
103#endif
104 if (point == NULL)
105 {
106 if (my_flags & MY_HOLD_ON_ERROR)
107 DBUG_RETURN(oldpoint);
108 if (my_flags & MY_FREE_ON_ERROR)
109 my_free(oldpoint);
110 my_errno=errno;
111 if (my_flags & (MY_FAE+MY_WME))
112 my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ ME_WAITTANG + ME_FATALERROR),
113 size);
114 DBUG_EXECUTE_IF("simulate_out_of_memory",
115 DBUG_SET("-d,simulate_out_of_memory"););
116 }
117#ifdef USE_HALLOC
118 else
119 {
120 memcpy(point,oldpoint,size);
121 free(oldpoint);
122 }
123#endif
124 DBUG_PRINT("exit",("ptr: %p", point));
125 DBUG_RETURN(point);
126}
127
128
129/**

Callers 15

my_str_realloc_mysqldFunction · 0.85
reallocMethod · 0.85
shrinkMethod · 0.85
my_yyoverflowFunction · 0.85
reallocMethod · 0.85
dynstr_setFunction · 0.85
dynstr_reallocFunction · 0.85
dynstr_append_memFunction · 0.85
alloc_dynamicFunction · 0.85
allocate_dynamicFunction · 0.85
freeze_sizeFunction · 0.85
my_realloc_cFunction · 0.85

Calls 3

my_mallocFunction · 0.85
my_freeFunction · 0.85
my_errorFunction · 0.85

Tested by

no test coverage detected