Issue #9823 has been updated by Heesob Park.


According to the document http://ruby-doc.org/stdlib-1.9.3/libdoc/dl/rdoc/DL/CPtr.html#method-c-malloc ,

~~~
DL::CPtr.malloc(size, freefunc = nil) => dl cptr instance
Allocate size bytes of memory and associate it with an optional freefunc that will be called when the pointer is garbage collected. freefunc must be an address pointing to a function or an instance of DL::CFunc.
~~~

The garbage collecting time is affected by the various conditions of code composition.


----------------------------------------
Bug #9823: Segmentation fault using DL
https://bugs.ruby-lang.org/issues/9823#change-46667

* Author: Christopher Hunt
* Status: Feedback
* Priority: Normal
* Assignee: Aaron Patterson
* Category: ext
* Target version: 
* ruby -v: ruby 1.9.3p545 (2014-02-24) [i386-mingw32]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
I receive a segmentation fault when calling OpenProcessToken from DL, demonstrated by running the attached 'runner.rb' file with the additional files in the same directory. This is a simplified representation, but perhaps not minimal, though with good reason. Doing any one of the following prevents a segmentation fault:
Copying line 3 from runner.rb to the bottom of mwe.rb and running mwe.rb directly.
Commenting out line 5 of mwe.rb or commenting out some large subset of errors.rb (e.g. commenting out lines 37 through 99 result in no segfault).
Commenting out line 3 of runner.rb, in effect only requiring the other files and exiting.
Commenting out a combination of the following from within Pageant::Win results in no segfault:
- Calls to extern
- Calls to struct
- Constants
- Class methods

In the last case it is not necessary to comment out all of the items of a particular category. For instance, a segfault is avoided if I comment out TOKEN_USER and SECURITY_ATTRIBUTES. I may also prevent a segfault by commenting out TOKEN_USER and the extern statement associated with IsValidSecurityDescriptor.

I have also tried this in the latest (ruby 2.1.2p95 (2014-05-08 revision 45867) [i386-mingw32]) with similar results. I've attached the error output for each of 1.9.3 and 2.1.2.

---Files--------------------------------
runner.rb (68 Bytes)


-- 
https://bugs.ruby-lang.org/