rthornton128 / goncurses

NCurses Library for Go
Other
383 stars 51 forks source link

Form gives a go garbage-collected pointer to the C function set_form_fields #21

Closed bvinc closed 9 years ago

bvinc commented 9 years ago

Steps to reproduce:

  1. Run the form example, or any program that uses goncurses forms with fields.
  2. Leave running for 10 or 15 minutes.
  3. Try to interact with the form.
  4. The program will segfault.

Expected results: The program doesn't segfault.

The reason this happens is because of SetFields on form.go line 211. It creates an array of CFIELD pointers and passes the CFIELD\ to set_form_fields. ncurses will save this pointer internally and expect that the memory will continue to be valid. However, since this is an array allocated by go, it's under the influence of the go garbage collector. After SetFields returns, it's only a matter of time before it is garbage collected, since no go pointer exists that points to this memory.

rthornton128 commented 9 years ago

Just back from a business trip where I was unable to respond. Will get to work on a fix as soon as I can.

If you already have something cooked up you can also submit a pull request.

rthornton128 commented 9 years ago

Fixed in commit 0b9eb14d568638603cf85f480e273eb8fe701721