@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() */
| 78 | error which is not the intention of realloc() |
| 79 | */ |
| 80 | void *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 |
| 102 | end: |
| 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 | /** |
no test coverage detected