# Memory crush somewhere in Socket

**URL:** <https://www.ruby-forum.com/t/memory-crush-somewhere-in-socket/74036>\
**Category:** Ruby\
**Created:** [October 29, 2006, 10:48am UTC](https://www.ruby-forum.com/t/memory-crush-somewhere-in-socket/74036 "2006-10-29T10:48:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/u/Victor_SZverokSS_Sh)\
**Post date:** [October 29, 2006, 10:48am UTC](https://www.ruby-forum.com/t/memory-crush-somewhere-in-socket/74036/1 "2006-10-29T10:48:37Z")

</div>

Hi all.

I have a very strange and uncommon problem.

I have Ruby version 1.9 from 13 oct 2006 on Windows XP.

I use some complex library from Ruby (large .dll + C extension I’ve  
written  
to talk to DLL from Ruby).

All works well, but when I try using the library together with  
Net::HTTP, I  
have segmentation faults.

The code looks like:

* * *

## Net::HTTP.get\_response ‘192.168.1.1’, ‘/index.html’ SomeLibrary.call\_some\_method

## The segfault appeared on second line, in the deeps in SomeLibrary.dll If I not using Net::HTTP calls in first line (instead, I read something from local file) - all works good. SomeLibrary’s author debugged the case and said “somebody shoot my memory”, like:

## HEAP[ruby.exe]: HEAP: Free Heap block 33a6e48 modified at 33a6e74 after it was freed

I’ve debugged (through dumb commenting/uncommenting lines) that the  
problem  
seems to be inside socket.readline inside HTTPResponse.read\_status\_line  
(net/http.rb, line 2017). Unfortuately, just now I have no advanced  
memory  
debugging tools to say something more concrete about who and how shoots  
the  
memory.

What can I do with this? I’d be happy to any advices!

(If it is important, SomeLibrary == HTMLayout, custom HTML layouting  
engine.  
It doesn’t use IE or Firefox, but it may use some Windows socket and  
inet  
API - can the problem lay here?)

Thanks.

V.

---

<div class="post-metadata">

**Author:** ![Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/u/Victor_SZverokSS_Sh)\
**Post date:** [October 29, 2006, 12:20pm UTC](https://www.ruby-forum.com/t/memory-crush-somewhere-in-socket/74036/2 "2006-10-29T12:20:41Z")

</div>

Victor “Zverok” Shepelev wrote:

> have segmentation faults.  
> local file) - all works good.  
> debugging tools to say something more concrete about who and how shoots the  
> memory.
> 
> What can I do with this? I’d be happy to any advices!
> 
> (If it is important, SomeLibrary == HTMLayout, custom HTML layouting engine.  
> It doesn’t use IE or Firefox, but it may use some Windows socket and inet  
> API - can the problem lay here?)

Sounds like a reasonable guess. Also, I do not understand why a HTML  
layouting lib needs sockets - especially in this case as you seem to  
pull the content via Net::HTTP. IMHO layout != transport - but then  
again I do not know this lib.

Good luck

```
robert
```

---

<div class="post-metadata">

**Author:** ![Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/u/Victor_SZverokSS_Sh)\
**Post date:** [October 29, 2006, 1:46pm UTC](https://www.ruby-forum.com/t/memory-crush-somewhere-in-socket/74036/3 "2006-10-29T13:46:46Z")

</div>

From: Robert K. [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
Sent: Sunday, October 29, 2006 1:20 PM

> > (If it is important, SomeLibrary == HTMLayout, custom HTML layouting  
> > engine.  
> > It doesn’t use IE or Firefox, but it may use some Windows socket and inet  
> > API - can the problem lay here?)
> 
> Sounds like a reasonable guess. Also, I do not understand why a HTML  
> layouting lib needs sockets - especially in this case as you seem to  
> pull the content via Net::HTTP. IMHO layout != transport - but then  
> again I do not know this lib.

You can look at the lib at [HTMLayout – Terra Informatica Software](http://terrainformatica.com/htmlayout/)

In short, it is not only layouting, but also url processing and loading;  
main goal is Rich Applications and Occasionally Connected Computing,  
thus it  
provides HTTP loading also.

But the question is still actual: how can I even try to debug this? I am  
semi-convinced that problem is definitely in Ruby’s extension.

v.

---

<div class="post-metadata">

**Author:** ![Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/u/Victor_SZverokSS_Sh)\
**Post date:** [October 29, 2006, 2:12pm UTC](https://www.ruby-forum.com/t/memory-crush-somewhere-in-socket/74036/4 "2006-10-29T14:12:48Z")

</div>

Hello !

> Net::HTTP.get\_response ‘192.168.1.1’, ‘/index.html’  
> SomeLibrary.call\_some\_method

Just out of curiosity, what happens when you swap these two calls ?  
Can you actually reproduce the bug with such a simple code (and just the  
loading of the libs) ? Could you post it, then ?

```
Vince
```

---

<div class="post-metadata">

**Author:** ![Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/u/Victor_SZverokSS_Sh)\
**Post date:** [October 29, 2006, 2:22pm UTC](https://www.ruby-forum.com/t/memory-crush-somewhere-in-socket/74036/5 "2006-10-29T14:22:48Z")

</div>

From: Vincent F. [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
Sent: Sunday, October 29, 2006 3:12 PM

> > Net::HTTP.get\_response ‘192.168.1.1’, ‘/index.html’  
> > SomeLibrary.call\_some\_method
> 
> Just out of curiosity, what happens when you swap these two calls ?

The case is more general: almost each call to  
SomeLibrary.almost\_any\_method  
crushes after Net::HTTP.get once was used.

> Can you actually reproduce the bug with such a simple code (and just the  
> loading of the libs) ?

Nope.

> Could you post it, then ?

In fact, I can (none of the code is confidential). But for it be useful  
for  
discussion, I should also “post” a bunch of libraries.  
OK, here is the program’s full text, and let’s look.

* * *

require ‘config’

require ‘htmr’  
require ‘htmr/extend’  
require ‘htmr/events’

require ‘net/http’

MAIN\_HTMR = ‘nanobrowser.htmr’

win = Htmr::Window.create\_from\_file(MAIN\_HTMR, ‘NanoBrowser’)

Net::HTTP.get\_response ‘192.168.1.1’, ‘/index.html’ #1

node = win.get(‘#url’)

## p node.window #2

Crashes at #2, if I’ll comment #1, all works as expected

Not looks very useful for understanding, yeah? :-\

V.

---

<div class="post-metadata">

**Author:** ![Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/u/Victor_SZverokSS_Sh)\
**Post date:** [October 29, 2006, 2:38pm UTC](https://www.ruby-forum.com/t/memory-crush-somewhere-in-socket/74036/6 "2006-10-29T14:38:49Z")

</div>

From: Vincent F. [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
Sent: Sunday, October 29, 2006 3:32 PM

> > Net::HTTP.get\_response ‘192.168.1.1’, ‘/index.html’ #1  
> > problems in the C wrapper you did write for the library ? That’s where I  
> > would look first…

Yep, I almost sure. I use this library alongside with wrapper last few  
monthes very intensively.

> But, if that’s not the case, you’ll need a debugger.

I have one (MS Visual C++). I just can’t understand, what definitely to  
debug :-\ HTTP::Net sources are rather huge, and its interaction with  
Socket  
are not very clear to me.

V.

---

<div class="post-metadata">

**Author:** ![Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/u/Victor_SZverokSS_Sh)\
**Post date:** [October 29, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/memory-crush-somewhere-in-socket/74036/7 "2006-10-29T17:47:21Z")

</div>

> > But, if that’s not the case, you’ll need a debugger.
> 
> I have one (MS Visual C++). I just can’t understand, what definitely to  
> debug :-\ HTTP::Net sources are rather huge, and its interaction with Socket  
> are not very clear to me.

Well, just rub your program until it triggers a memory fault, and  
display a backtrace here; it might give you useful information. It might  
not, as well…

For gdb, I would just use

gdb ruby

> run script.rb

I don’t know how to use the MS debugger, but I expect it would be the  
same…

```
Vince
```

---

<div class="post-metadata">

**Author:** ![Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@Victor\_SZverokSS\_Sh](https://www.ruby-forum.com/u/Victor_SZverokSS_Sh)\
**Post date:** [October 29, 2006, 2:32pm UTC](https://www.ruby-forum.com/t/memory-crush-somewhere-in-socket/74036/8 "2006-10-29T14:32:49Z")

</div>

Victor “Zverok” Shepelev wrote:

> require ‘htmr/extend’  
> node = win.get(’#url’)
> 
> p node.window #2
> 
> Crashes at #2, if I’ll comment #1, all works as expected
> 
> Not looks very useful for understanding, yeah? :-\

Somehow puzzling… You’re sure you don’t have memory allocation  
problems in the C wrapper you did write for the library ? That’s where I  
would look first… But, if that’s not the case, you’ll need a debugger.

```
Vince
```
