Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix leak reported by Valgrind when setting environment variables
The call to setenv replaces the string in the environ array, which causes the original string to be reported as a memory leak. This commit allocates another copy of environ called alloc_environ that contains the strings allocated by ruby_init_setproctitle. Then in ruby_free_proctitle it frees all the strings in alloc_environ. For example: ENV.each { |k, v| ENV[k] = v.dup } Valgrind reports: 3,321 bytes in 39 blocks are definitely lost in loss record 3 of 3 at 0x484884F: malloc (vg_replace_malloc.c:393) by 0x25CB5B: objspace_xmalloc0 (gc.c:11972) by 0x40344E: ruby_strdup (util.c:540) by 0x59C854: ruby_init_setproctitle (setproctitle.c:143) by 0x38CC44: ruby_process_options (ruby.c:3101) by 0x234DB1: ruby_options (eval.c:117) by 0x15B92E: rb_main (main.c:40) by 0x15B92E: main (main.c:59)
- Loading branch information