MCPcopy Create free account
hub / github.com/acl-dev/acl / acl_default_malloc

Function acl_default_malloc

lib_acl/src/stdlib/memory/acl_default_malloc.c:188–247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186#ifdef SAFE_MEM
187
188void *acl_default_malloc(const char *filename, int line, size_t len)
189{
190 const char *myname = "acl_default_malloc";
191 size_t new_len;
192 char *ptr;
193 MBLOCK *real_ptr;
194 const char *pname = NULL;
195
196#if 0
197 printf("%s:%d, len: %d\r\n", filename, line, (int) len);
198 acl_trace_info();
199#endif
200
201 if (filename && *filename) {
202 SET_FILE(pname, filename);
203 } else {
204 pname = __FILENAME_UNKNOWN;
205 }
206
207 if (len < 1) {
208 acl_msg_warn("%s(%d), %s: malloc: length %ld invalid",
209 pname, line, myname, (long) len);
210 acl_trace_info();
211 len = 128;
212 }
213
214 new_len = SPACE_FOR(len);
215 if (new_len <= 0) {
216 acl_msg_fatal("%s(%d): new_len(%d) <= 0",
217 myname, __LINE__, (int) new_len);
218 } else if (new_len >= __malloc_limit) {
219 acl_msg_warn("%s(%d): new_len(%d) too large",
220 myname, __LINE__, (int) new_len);
221 acl_trace_info();
222 }
223
224#ifdef DEBUG_MEM
225 __nmalloc++;
226 __nsize += len;
227 //printf("malloc: %llu, filename=%s, line=%d\r\n", __nmalloc, filename, line);
228#endif
229
230#ifdef _USE_GLIB
231 if ((real_ptr = (MBLOCK *) g_malloc(new_len)) == 0) {
232 acl_msg_error("%s(%d)->%s: new_len: %d, g_malloc error(%s)",
233 pname, line, myname, (int) new_len, strerror(errno));
234 return 0;
235 }
236#else
237 if ((real_ptr = (MBLOCK *) malloc(new_len)) == 0) {
238 acl_msg_error("%s(%d)->%s: malloc: insufficient memory: %s, "
239 "new_len: %d", pname, line, myname,
240 strerror(errno), (int) new_len);
241 return 0;
242 }
243#endif
244
245 CHECK_OUT_PTR(ptr, real_ptr, len);

Callers 12

memPoolAllocFunction · 0.85
acl_default_reallocFunction · 0.85
acl_default_callocFunction · 0.85
acl_default_strdupFunction · 0.85
acl_default_strndupFunction · 0.85
acl_default_memdupFunction · 0.85
stack_growFunction · 0.85
fifo_pushFunction · 0.85
acl_pthread_setspecificFunction · 0.85
acl_pthread_atexit_addFunction · 0.85
acl_pthread_tls_getFunction · 0.85

Calls 5

acl_trace_infoFunction · 0.85
acl_msg_warnFunction · 0.85
acl_msg_fatalFunction · 0.85
acl_msg_errorFunction · 0.85
mallocFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…