Class: RubyMemcheck::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_memcheck/stack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, stack_xml) ⇒ Stack

Returns a new instance of Stack.



7
8
9
10
# File 'lib/ruby_memcheck/stack.rb', line 7

def initialize(configuration, stack_xml)
  @configuration = configuration
  @frames = stack_xml.xpath("frame").map { |frame| Frame.new(configuration, frame) }
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



5
6
7
# File 'lib/ruby_memcheck/stack.rb', line 5

def configuration
  @configuration
end

#framesObject (readonly)

Returns the value of attribute frames.



5
6
7
# File 'lib/ruby_memcheck/stack.rb', line 5

def frames
  @frames
end

Instance Method Details

#skip?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ruby_memcheck/stack.rb', line 12

def skip?
  in_binary = false

  frames.each do |frame|
    fn = frame.fn

    if frame.in_ruby?
      # If a stack from from the binary was encountered first, then this
      # memory leak did not occur from Ruby
      unless in_binary
        # Skip this stack because it was called from Ruby
        return true if configuration.skipped_ruby_functions.any? { |r| r.match?(fn) }
      end
    elsif frame.in_binary?
      in_binary = true

      # Skip the Init function because it is only ever called once, so
      # leaks in it cannot cause memory bloat
      return true if fn == "Init_#{configuration.binary_name}"
    end
  end

  # Skip if the stack was never in the binary because it is very likely
  # not a leak in the native gem
  !in_binary
end