libchewing icon indicating copy to clipboard operation
libchewing copied to clipboard

C API chewing_get_selKey returns pointer to static data

Open kanru opened this issue 11 months ago • 0 comments

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:

  1. Call chewing_get_selKey
  2. Call free() on the returned pointer
  3. 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.

kanru avatar Jan 04 '25 13:01 kanru