aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-08 17:52:38 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-08 17:52:38 +0000
commit0b376f80829ec91f8108826fa5c3144fc50f7bf9 (patch)
tree24d96826c2e0f47497f8f45df33121c17b5bc6b7
parent6a321eb96447fbbeb319a47fdad902c9d90db991 (diff)
downloadruby-0b376f80829ec91f8108826fa5c3144fc50f7bf9.tar.gz
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54954 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog11
-rw-r--r--gc.c6
-rw-r--r--regparse.c5
-rw-r--r--util.c4
4 files changed, 22 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 17948762ae..5c2434793f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Mon May 9 02:51:51 2016 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* configure.in: check function attirbute const and pure,
diff --git a/gc.c b/gc.c
index 92885754a4..0f1bbc7305 100644
--- a/gc.c
+++ b/gc.c
@@ -5962,6 +5962,7 @@ rb_gc_unprotect_logging(void *objptr, const char *filename, int line)
}
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 *objspace, int reason)
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");
diff --git a/regparse.c b/regparse.c
index d3907de7d9..f405f5481b 100644
--- a/regparse.c
+++ b/regparse.c
@@ -6460,7 +6460,10 @@ parse_regexp(Node** top, UChar** src, UChar* end, ScanEnv* env)
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
diff --git a/util.c b/util.c
index 95ac2b09b5..5c89eb6947 100644
--- a/util.c
+++ b/util.c
@@ -748,12 +748,12 @@ ruby_getcwd(void)
#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