# Memory leaks

**URL:** <https://www.ruby-forum.com/t/memory-leaks/144865>\
**Category:** Development\
**Created:** [August 3, 2008, 4:00pm UTC](https://www.ruby-forum.com/t/memory-leaks/144865 "2008-08-03T16:00:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shinichiro.h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@shinichiro.h](https://www.ruby-forum.com/u/shinichiro.h)\
**Post date:** [August 3, 2008, 4:00pm UTC](https://www.ruby-forum.com/t/memory-leaks/144865/1 "2008-08-03T16:00:54Z")

</div>

e$BIMCO$G$9!#e(B

test/ruby e$B0J2\<$re(B valgrind e$B$+$1$F$_$?$ie(B  
e$B?’!9$H$"$C$?$h$&$J$N$G=$@5$7$F$_$^$7$?!#e(B

- marshal.c

Marshal.dump(‘hoge’)

e$B$G%j!\<%/$7$^$9!#e(B

- process.c

IO.popen([“echo bar”]) {}

e$B$G%j!\<%/$7$^$9!#e(B

- string.c

s = “foo” \* 100  
s2 = “foo” \* 101  
s.replace(s2)

e$B$G%j!\<%/$7$^$9!#e(B

- transcode.c

e$BFq2r$G$"$^$j$h$/$o$+$C$F$^$;$s$,!"e(B  
test\_transcode.rb e$B$,%j!\<%/$7$F$^$7$?!#e(B  
e$B\>e$Ne(B while e$B$b2?$+4V0c$C$F$k$H;W$&$N$G$9$,!#e(B

e$B$"$He(B test\_regexp.rb e$B$bE$i$l$F$^$7$?$,!"e(B  
e$BFq$7$=$&$J$N$GD|$a$^$7$?!#e(B

# Index: marshal.c

— marshal.c (revision 18324)  
+++ marshal.c (working copy)  
@@ -803,6 +803,7 @@  
st\_free\_table(arg-\>symbols);  
st\_free\_table(arg-\>data);  
st\_free\_table(arg-\>compat\_tbl);

- if (arg-\>encodings) st\_free\_table(arg-\>encodings);  
DATA\_PTR(arg-\>wrapper) = 0;  
arg-\>wrapper = 0;  
if (arg-\>taint) {  
Index: process.c  
===================================================================  
— process.c (revision 18324)  
+++ process.c (working copy)  
@@ -1953,6 +1953,8 @@  
goto fail;  
}

- if (pairs)

- 

```
   xfree(pairs);

```

return 0;

# fail: Index: string.c

— string.c (revision 18324)  
+++ string.c (working copy)  
@@ -453,6 +453,9 @@  
static VALUE  
str\_replace\_shared(VALUE str2, VALUE str)  
{

- if (!STR\_EMBED\_P(str2) && !STR\_SHARED\_P(str2)) {
- xfree(RSTRING(str2)-\>as.heap.ptr);
- }  
if (RSTRING\_LEN(str) \<= RSTRING\_EMBED\_LEN\_MAX) {  
STR\_SET\_EMBED(str2);  
memcpy(RSTRING\_PTR(str2), RSTRING\_PTR(str), RSTRING\_LEN(str)+1);  
Index: transcode.c  
===================================================================  
— transcode.c (revision 18324)  
+++ transcode.c (working copy)  
@@ -110,6 +110,7 @@  
}  
if (!val) {  
if (!st\_lookup(transcoder\_table, (st\_data\_t)key, &val)) {
- 

```
 xfree(key);
 /* multistep logic, via UTF-8 */
 if (!encoding_equal(from_encoding, "UTF-8") &&

```

!encoding\_equal(to\_encoding, “UTF-8”) &&  
@@ -119,6 +120,7 @@  
return NULL;  
}  
}
- xfree(key);  
return (rb\_transcoder \*)val;  
}
