-
Notifications
You must be signed in to change notification settings - Fork 11.7k
tools : fix invalid free() #13436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tools : fix invalid free() #13436
Conversation
…uctor's call to llama_batch_free from causing an invalid free()
There are other ways to solve this if you don't want to zero out the entire llama_batch object. (eg track whether server_context::init() has been called, check in the destructor before calling llama_batch_free) |
I think the proper fix is to check if |
Both |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok that makes sense. I think this can be the temporary solution before we finally have the private batch API.
Co-authored-by: Xuan-Son Nguyen <[email protected]>
tools/server/server.cpp
Outdated
@@ -1884,6 +1884,7 @@ struct server_context { | |||
|
|||
common_chat_templates_ptr chat_templates; | |||
|
|||
server_context() : batch({}) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could just use llama_batch batch = {};
in the field declaration on line 1865 to keep the default noexcept constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize you could initialize non-scalar members in that way. I went ahead and updated this PR to use 'direct-list-initialization' as described here: https://en.cppreference.com/w/cpp/language/list_initialization
Added a constructor to server_context that initializes server_context::batch, preventing the destructor's call to llama_batch_free() from causing an invalid free().
Ran into this when bind() failed.