ggml : fix for non-virtual destructor issue of gguf_writer_base#25867
Open
yymin1022 wants to merge 1 commit into
Open
ggml : fix for non-virtual destructor issue of gguf_writer_base#25867yymin1022 wants to merge 1 commit into
yymin1022 wants to merge 1 commit into
Conversation
…gguf_writer_base Without a virtual destructor, deleting a derived object through a base-class pointer only invokes the base destructor, skipping the derived one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
gguf_writer_basedeclares virtual member functions but its destructorwas non-virtual. Deleting a derived writer instance through a
gguf_writer_base*(or any base-class pointer/reference) skips thederived class's destructor, because it is not virtual.
This can leak resources owned by the derived writer and is undefined behavior per the C++
standard when the dynamic type differs from the static type at the
point of deletion.
Change
Add
virtualtogguf_writer_base's destructor inggml/src/gguf.cpp.Additional information
Found while cross-compiling ggml/llama.cpp as a static library inside
an AOSP tree (vendor partition), which enables
-Werror=non-virtual-dtorunconditionally by AOSP build rule.Confirmed the class has no other polymorphic-deletion issues after the fix; build completes
cleanly with this flag enabled.
No functional change to existing single-inheritance, base-pointer-free
usage; this only affects correctness when a derived writer is deleted
via a base pointer, which is the intended usage pattern given the
virtual methods already present on the class.
Requirements