libchewing
libchewing copied to clipboard
C API chewing_get_selKey returns pointer to static data
Describe the bug
chewing_get_selKey used to return a pointer to new malloc'ed memory, which is safe to be deallocated by free()
Now it returns a pointer to a per ChewingContext data structure, it's no longer safe to free() it and it's not thread safe.
To Reproduce Steps to reproduce the behavior:
- Call
chewing_get_selKey - Call
free()on the returned pointer - Sometimes this causes a crash.
Expected behavior
New memory should be allocated every time.
Platform (please complete the following information):
- OS: All
- Version: 0.8.0
Additional context
Currently chewing_free() ignores invalid pointer - so programs following the doc and always free chewing objects with chewing_free() are not affected. Freeing chewing objects with system libc free() invokes undefined behavior.