Skip to content
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

C API chewing_get_selKey returns pointer to static data #671

Open
kanru opened this issue Jan 4, 2025 · 0 comments
Open

C API chewing_get_selKey returns pointer to static data #671

kanru opened this issue Jan 4, 2025 · 0 comments
Labels
Milestone

Comments

@kanru
Copy link
Member

kanru commented Jan 4, 2025

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 kanru added the bug label Jan 4, 2025
@kanru kanru added this to the v0.10.0 milestone Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant