diff options
author | 2016-01-04 04:06:13 +0000 | |
---|---|---|
committer | 2016-01-04 04:06:13 +0000 | |
commit | cc00b13b9259fc957d7f1698db49f283037298af (patch) | |
tree | 8ead5074561428ad20c5cd0fdaa92c804f34310e /src/lib/util/corealloc.cpp | |
parent | 823a779de2763f6834eb3f5db727348ddf09ac85 (diff) | |
parent | a3f2c5abcd892fec0aeffbb0d661490bcf295108 (diff) |
Merge branch 'master' of https://github.com/mamedev/mame
Diffstat (limited to 'src/lib/util/corealloc.cpp')
-rw-r--r-- | src/lib/util/corealloc.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/lib/util/corealloc.cpp b/src/lib/util/corealloc.cpp index 38f21846f96..eaf0ff40420 100644 --- a/src/lib/util/corealloc.cpp +++ b/src/lib/util/corealloc.cpp @@ -222,6 +222,44 @@ void free_file_line(void *memory, const char *file, int line, bool array) osd_free(memory); } +void *realloc_internal(void *memory, size_t size, const char *file, int line, bool array) +{ + fprintf(stderr, "realloc_internal called for %p in %s(%d)!\n", memory, file, line); + if(size == 0) { + return nullptr; + } + if(memory == nullptr) { + return malloc_file_line(size, file, line, array, false, false); + } + // find the memory entry + memory_entry *entry = memory_entry::find(memory); + + // warn about untracked reallocs + if (entry == nullptr) + { + fprintf(stderr, "Error: attempt to realloc untracked memory %p in %s(%d)!\n", memory, file, line); + osd_break_into_debugger("Error: attempt to realloc untracked memory"); + return memory; + } + + // this is used internally and should always be an array + if(!array || !entry->m_array) + { + fprintf(stderr, "Error: attempt to realloc non-array memory %p in %s(%d). realloc_internal should never be called directly!\n", memory, file, line); + osd_break_into_debugger("Error: attempt to realloc non-array memory"); + } + + size_t o_size = entry->m_size; + void *new_buf = malloc_file_line(size, file, line, array, false, false); + if(new_buf == nullptr) { + fprintf(stderr, "Error: realloc: unable to allocate new buffer %p in %s(%d)!\n", memory, file, line); + return nullptr; + } + memcpy(new_buf, memory, (o_size < size) ? o_size : size); + free_file_line(memory, file, line, array); + return new_buf; +} + //------------------------------------------------- // track_memory - enables or disables the memory |