Skip to content

Commit daf222c

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Handle memory limit error during string reallocation correctly
2 parents 6b521a9 + 0fc65ed commit daf222c

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Zend/zend_string.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,13 @@ static zend_always_inline zend_string *zend_string_realloc(zend_string *s, size_
205205
ZSTR_LEN(ret) = len;
206206
zend_string_forget_hash_val(ret);
207207
return ret;
208-
} else {
209-
GC_DELREF(s);
210208
}
211209
}
212210
ret = zend_string_alloc(len, persistent);
213211
memcpy(ZSTR_VAL(ret), ZSTR_VAL(s), MIN(len, ZSTR_LEN(s)) + 1);
212+
if (!ZSTR_IS_INTERNED(s)) {
213+
GC_DELREF(s);
214+
}
214215
return ret;
215216
}
216217

@@ -225,12 +226,13 @@ static zend_always_inline zend_string *zend_string_extend(zend_string *s, size_t
225226
ZSTR_LEN(ret) = len;
226227
zend_string_forget_hash_val(ret);
227228
return ret;
228-
} else {
229-
GC_DELREF(s);
230229
}
231230
}
232231
ret = zend_string_alloc(len, persistent);
233232
memcpy(ZSTR_VAL(ret), ZSTR_VAL(s), ZSTR_LEN(s) + 1);
233+
if (!ZSTR_IS_INTERNED(s)) {
234+
GC_DELREF(s);
235+
}
234236
return ret;
235237
}
236238

@@ -245,12 +247,13 @@ static zend_always_inline zend_string *zend_string_truncate(zend_string *s, size
245247
ZSTR_LEN(ret) = len;
246248
zend_string_forget_hash_val(ret);
247249
return ret;
248-
} else {
249-
GC_DELREF(s);
250250
}
251251
}
252252
ret = zend_string_alloc(len, persistent);
253253
memcpy(ZSTR_VAL(ret), ZSTR_VAL(s), len + 1);
254+
if (!ZSTR_IS_INTERNED(s)) {
255+
GC_DELREF(s);
256+
}
254257
return ret;
255258
}
256259

@@ -264,12 +267,13 @@ static zend_always_inline zend_string *zend_string_safe_realloc(zend_string *s,
264267
ZSTR_LEN(ret) = (n * m) + l;
265268
zend_string_forget_hash_val(ret);
266269
return ret;
267-
} else {
268-
GC_DELREF(s);
269270
}
270271
}
271272
ret = zend_string_safe_alloc(n, m, l, persistent);
272273
memcpy(ZSTR_VAL(ret), ZSTR_VAL(s), MIN((n * m) + l, ZSTR_LEN(s)) + 1);
274+
if (!ZSTR_IS_INTERNED(s)) {
275+
GC_DELREF(s);
276+
}
273277
return ret;
274278
}
275279

0 commit comments

Comments
 (0)