Menu

#1 static VALUE variables in C code provokes core dump

open
nobody
None
5
2008-04-17
2008-04-17
RNicz
No

There are two static VALUE variables used in code for Shape#inspect method and in function used in code for Shape#part_start. In current version both methods causes core dumps when used several times. I suppose that they are not bound to symbol so they are deallocated by garbage collector soon after initialization.

Here is code for Shape#inspect bug reproduction

---
require 'shapelib'

ShapeLib::ShapeFile::open(ARGV[0]) do
|sf|
$stderr.puts('inspect test')
sf.each do
|s|
a=s.inspect
end
end
---

Reproduction of bug in Shape#part_start is somewhat more complicated

---
require 'shapelib'

def loops(parts, xvals, yvals)
o=[]
if parts
parts.each_index do
|idx|
o << []
(parts[idx]..(parts[idx+1] || (xvals.size-1))).each do
|i|
o.last << [xvals[i],yvals[i]]
end
end
end
o
end

if __FILE__==$0
ShapeLib::ShapeFile::open(ARGV[0]) do
|sf|
$stderr.puts('part_start test')
1000000.times do
$stderr.puts("\nshape start")
sf.each do
|s|
bd = loops(s.part_start, s.xvals, s.yvals)
pg=ShapeLib::Polygon.new(*bd)
end
end
end
end
---

I attach patch which corrects this problems.

--
Best regards
RNicz

Discussion

  • RNicz

    RNicz - 2008-04-17

    Strip 'static' from VALUE variables

     
  • Anonymous

    Anonymous - 2008-04-29

    Logged In: YES
    user_id=891257
    Originator: NO

    This patch also works, and avoids calling rb_str_new2 repeatedly
    so performance should not be impacted.

    <pre>
    --- a/valconv.h
    +++ b/valconv.h
    @@ -298,6 +298,7 @@ static VALUE IntUnpack(int *up, unsigned num)
    if (unpackfmt == 0) {
    unpackid = rb_intern("unpack");
    unpackfmt = rb_str_new2("i*");
    + rb_global_variable(&amp;unpackfmt);
    }
    buf = rb_str_new((char *)up, sizeof(int) * num);
    return rb_funcall(buf, unpackid, 1, unpackfmt);
    </pre>

     
  • Nobody/Anonymous

    Are you sure that fixes it? I've made that change locally and I still get the error on MacOS X

     
  • Nobody/Anonymous

    Sorry, I don't have an account but can be reached at mmangino@elevatedrails.com

    I also have a version of this code at http://github.com/mmangino/shapelib/tree/master

    Mike

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.