diff --git a/chat.cpp b/chat.cpp index 22f0a4ddf4a05..befd6d9d6c0d0 100644 --- a/chat.cpp +++ b/chat.cpp @@ -1,7 +1,5 @@ #include "ggml.h" - #include "utils.h" - #include #include #include @@ -561,12 +559,18 @@ bool llama_eval( // reallocate buf_size = buf_size_new; - buf = realloc(buf, buf_size); - if (buf == nullptr) { - fprintf(stderr, "%s: failed to allocate %zu bytes\n", __func__, buf_size); - return false; + + void * tmp = realloc(buf, buf_size); + if (NULL == tmp) + { + fprintf(stderr, "%s: failed to allocate %zu bytes\n", __func__, buf_size); + return false; } - } + else + { + buf = tmp; + } + } struct ggml_init_params params = { /*.mem_size =*/ buf_size,