@@ -46,6 +46,9 @@ int be_re_compile(bvm *vm) {
46
46
}
47
47
48
48
ByteProg * code = be_os_malloc (sizeof (ByteProg ) + sz );
49
+ if (code == NULL ) {
50
+ be_throw (vm , BE_MALLOC_FAIL ); /* lack of heap space */
51
+ }
49
52
int ret = re1_5_compilecode (code , regex_str );
50
53
if (ret != 0 ) {
51
54
be_raise (vm , "internal_error" , "error in regex" );
@@ -113,11 +116,16 @@ int be_re_match_search(bvm *vm, bbool is_anchored, bbool size_only) {
113
116
}
114
117
115
118
ByteProg * code = be_os_malloc (sizeof (ByteProg ) + sz );
119
+ if (code == NULL ) {
120
+ be_throw (vm , BE_MALLOC_FAIL ); /* lack of heap space */
121
+ }
116
122
int ret = re1_5_compilecode (code , regex_str );
117
123
if (ret != 0 ) {
124
+ be_os_free (code );
118
125
be_raise (vm , "internal_error" , "error in regex" );
119
126
}
120
127
be_re_match_search_run (vm , code , hay , is_anchored , size_only );
128
+ be_os_free (code );
121
129
be_return (vm );
122
130
}
123
131
be_raise (vm , "type_error" , NULL );
@@ -138,8 +146,12 @@ int be_re_match_search_all(bvm *vm, bbool is_anchored) {
138
146
}
139
147
140
148
ByteProg * code = be_os_malloc (sizeof (ByteProg ) + sz );
149
+ if (code == NULL ) {
150
+ be_throw (vm , BE_MALLOC_FAIL ); /* lack of heap space */
151
+ }
141
152
int ret = re1_5_compilecode (code , regex_str );
142
153
if (ret != 0 ) {
154
+ be_os_free (code );
143
155
be_raise (vm , "internal_error" , "error in regex" );
144
156
}
145
157
@@ -152,6 +164,7 @@ int be_re_match_search_all(bvm *vm, bbool is_anchored) {
152
164
be_pop (vm , 1 );
153
165
}
154
166
be_pop (vm , 1 );
167
+ be_os_free (code );
155
168
be_return (vm );
156
169
}
157
170
be_raise (vm , "type_error" , NULL );
@@ -328,11 +341,17 @@ int be_re_split(bvm *vm) {
328
341
}
329
342
330
343
ByteProg * code = be_os_malloc (sizeof (ByteProg ) + sz );
344
+ if (code == NULL ) {
345
+ be_throw (vm , BE_MALLOC_FAIL ); /* lack of heap space */
346
+ }
331
347
int ret = re1_5_compilecode (code , regex_str );
332
348
if (ret != 0 ) {
349
+ be_os_free (code );
333
350
be_raise (vm , "internal_error" , "error in regex" );
334
351
}
335
- return re_pattern_split_run (vm , code , hay , split_limit );
352
+ ret = re_pattern_split_run (vm , code , hay , split_limit );
353
+ be_os_free (code );
354
+ return ret ;
336
355
}
337
356
be_raise (vm , "type_error" , NULL );
338
357
}
0 commit comments