[前][次][番号順一覧][スレッド一覧]

ruby-changes:42880

From: naruse <ko1@a...>
Date: Mon, 9 May 2016 01:56:02 +0900 (JST)
Subject: [ruby-changes:42880] naruse:r54954 (trunk): * gc.c (rb_gc_unprotect_logging): throw rb_memerror when it cannot

naruse	2016-05-09 02:52:38 +0900 (Mon, 09 May 2016)

  New Revision: 54954

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54954

  Log:
    * gc.c (rb_gc_unprotect_logging): throw rb_memerror when it cannot
      allocate memory. This is pointed out by Facebook's Infer.
    
    * gc.c (gc_prof_setup_new_record): ditto.
    
    * regparse.c (parse_regexp): ditto.
    
    * util.c (MALLOC): use xmalloc and xfree like above.

  Modified files:
    trunk/ChangeLog
    trunk/gc.c
    trunk/regparse.c
    trunk/util.c
Index: gc.c
===================================================================
--- gc.c	(revision 54953)
+++ gc.c	(revision 54954)
@@ -5962,6 +5962,7 @@ rb_gc_unprotect_logging(void *objptr, co https://github.com/ruby/ruby/blob/trunk/gc.c#L5962
 	}
 	else {
 	    ptr = (char *)malloc(strlen(buff) + 1);
+	    if (!ptr) rb_memerror();
 	    strcpy(ptr, buff);
 	}
 	st_insert(rgengc_unprotect_logging_table, (st_data_t)ptr, cnt);
@@ -8523,8 +8524,11 @@ gc_prof_setup_new_record(rb_objspace_t * https://github.com/ruby/ruby/blob/trunk/gc.c#L8524
 	    objspace->profile.records = malloc(sizeof(gc_profile_record) * objspace->profile.size);
 	}
 	if (index >= objspace->profile.size) {
+	    void *ptr;
 	    objspace->profile.size += 1000;
-	    objspace->profile.records = realloc(objspace->profile.records, sizeof(gc_profile_record) * objspace->profile.size);
+	    ptr = realloc(objspace->profile.records, sizeof(gc_profile_record) * objspace->profile.size);
+	    if (!ptr) rb_memerror();
+	    objspace->profile.records = ptr;
 	}
 	if (!objspace->profile.records) {
 	    rb_bug("gc_profile malloc or realloc miss");
Index: util.c
===================================================================
--- util.c	(revision 54953)
+++ util.c	(revision 54954)
@@ -748,12 +748,12 @@ ruby_getcwd(void) https://github.com/ruby/ruby/blob/trunk/util.c#L748
 #ifdef MALLOC
 extern void *MALLOC(size_t);
 #else
-#define MALLOC malloc
+#define MALLOC xmalloc
 #endif
 #ifdef FREE
 extern void FREE(void*);
 #else
-#define FREE free
+#define FREE xfree
 #endif
 
 #ifndef Omit_Private_Memory
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54953)
+++ ChangeLog	(revision 54954)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon May  9 02:51:51 2016  NARUSE, Yui  <naruse@r...>
+
+	* gc.c (rb_gc_unprotect_logging): throw rb_memerror when it cannot
+	  allocate memory. This is pointed out by Facebook's Infer.
+
+	* gc.c (gc_prof_setup_new_record): ditto.
+
+	* regparse.c (parse_regexp): ditto.
+
+	* util.c (MALLOC): use xmalloc and xfree like above.
+
 Mon May  9 02:39:16 2016  NARUSE, Yui  <naruse@r...>
 
 	* configure.in: check function attirbute const and pure,
Index: regparse.c
===================================================================
--- regparse.c	(revision 54953)
+++ regparse.c	(revision 54954)
@@ -6460,7 +6460,10 @@ parse_regexp(Node** top, UChar** src, UC https://github.com/ruby/ruby/blob/trunk/regparse.c#L6460
     NENCLOSE(np)->regnum = num;
     NENCLOSE(np)->target = *top;
     r = scan_env_set_mem_node(env, num, np);
-    if (r != 0) return r;
+    if (r != 0) {
+	onig_node_free(np);
+	return r;
+    }
     *top = np;
   }
 #endif

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]