| 186 | #ifdef SAFE_MEM |
| 187 | |
| 188 | void *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); |
no test coverage detected
searching dependent graphs…