[ruby-core:68110] [Ruby trunk - Bug #10853] [Assigned] inspect.claer dumps core

From: mame@...
Date: 2015-02-13 12:41:58 UTC
List: ruby-core #68110
Issue #10853 has been reported by Yusuke Endoh.

----------------------------------------
Bug #10853: inspect.claer dumps core
https://bugs.ruby-lang.org/issues/10853

* Author: Yusuke Endoh
* Status: Assigned
* Priority: Normal
* Assignee: Yusuke Endoh
* ruby -v: ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
~~~
$ ruby -e 'inspect.clear'
*** Error in `ruby': munmap_chunk(): invalid pointer: 0x00007fd20ed64fe7 ***
Aborted (core dumped)
~~~

str_discard attempts to free a C literal string, which causes core dump.
It must check STR_NOFREE.

~~~
diff --git a/string.c b/string.c
index 5de795a..d810213 100644
--- a/string.c
+++ b/string.c
@@ -1662,7 +1662,7 @@ static inline void
 str_discard(VALUE str)
 {
     str_modifiable(str);
-    if (!STR_SHARED_P(str) && !STR_EMBED_P(str)) {
+    if (!STR_EMBED_P(str) && !FL_TEST(str, STR_SHARED|STR_NOFREE)) {
        ruby_sized_xfree(STR_HEAP_PTR(str), STR_HEAP_SIZE(str));
        RSTRING(str)->as.heap.ptr = 0;
        RSTRING(str)->as.heap.len = 0;
~~~

-- 
Yusuke Endoh <mame@ruby-lang.org>



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

In This Thread

Prev Next