Skip to content

Commit 0bc9ca3

Browse files
committed
Refactor to using a stack based zval instead of dynamic allocation
1 parent 37b2207 commit 0bc9ca3

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

ext/standard/password.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,11 @@ PHP_FUNCTION(password_needs_rehash)
245245

246246
if (options && zend_symtable_find(options, "cost", sizeof("cost"), (void **) &option_buffer) == SUCCESS) {
247247
if (Z_TYPE_PP(option_buffer) != IS_LONG) {
248-
zval *cast_option_buffer;
249-
ALLOC_ZVAL(cast_option_buffer);
250-
MAKE_COPY_ZVAL(option_buffer, cast_option_buffer);
251-
convert_to_long(cast_option_buffer);
252-
new_cost = Z_LVAL_P(cast_option_buffer);
253-
zval_ptr_dtor(&cast_option_buffer);
248+
zval cast_option_buffer;
249+
MAKE_COPY_ZVAL(option_buffer, &cast_option_buffer);
250+
convert_to_long(&cast_option_buffer);
251+
new_cost = Z_LVAL(cast_option_buffer);
252+
zval_dtor(&cast_option_buffer);
254253
} else {
255254
new_cost = Z_LVAL_PP(option_buffer);
256255
}
@@ -326,12 +325,11 @@ PHP_FUNCTION(password_hash)
326325

327326
if (options && zend_symtable_find(options, "cost", 5, (void **) &option_buffer) == SUCCESS) {
328327
if (Z_TYPE_PP(option_buffer) != IS_LONG) {
329-
zval *cast_option_buffer;
330-
ALLOC_ZVAL(cast_option_buffer);
331-
MAKE_COPY_ZVAL(option_buffer, cast_option_buffer);
332-
convert_to_long(cast_option_buffer);
333-
cost = Z_LVAL_P(cast_option_buffer);
334-
zval_ptr_dtor(&cast_option_buffer);
328+
zval cast_option_buffer;
329+
MAKE_COPY_ZVAL(option_buffer, &cast_option_buffer);
330+
convert_to_long(&cast_option_buffer);
331+
cost = Z_LVAL(cast_option_buffer);
332+
zval_dtor(&cast_option_buffer);
335333
} else {
336334
cost = Z_LVAL_PP(option_buffer);
337335
}
@@ -366,17 +364,16 @@ PHP_FUNCTION(password_hash)
366364
case IS_LONG:
367365
case IS_DOUBLE:
368366
case IS_OBJECT: {
369-
zval *cast_option_buffer;
370-
ALLOC_ZVAL(cast_option_buffer);
371-
MAKE_COPY_ZVAL(option_buffer, cast_option_buffer);
372-
convert_to_string(cast_option_buffer);
373-
if (Z_TYPE_P(cast_option_buffer) == IS_STRING) {
374-
buffer = estrndup(Z_STRVAL_P(cast_option_buffer), Z_STRLEN_P(cast_option_buffer));
375-
buffer_len_int = Z_STRLEN_P(cast_option_buffer);
376-
zval_ptr_dtor(&cast_option_buffer);
367+
zval cast_option_buffer;
368+
MAKE_COPY_ZVAL(option_buffer, &cast_option_buffer);
369+
convert_to_string(&cast_option_buffer);
370+
if (Z_TYPE(cast_option_buffer) == IS_STRING) {
371+
buffer = estrndup(Z_STRVAL(cast_option_buffer), Z_STRLEN(cast_option_buffer));
372+
buffer_len_int = Z_STRLEN(cast_option_buffer);
373+
zval_dtor(&cast_option_buffer);
377374
break;
378375
}
379-
zval_ptr_dtor(&cast_option_buffer);
376+
zval_dtor(&cast_option_buffer);
380377
}
381378
case IS_BOOL:
382379
case IS_NULL:

0 commit comments

Comments
 (0)