Skip to content

Commit 044de83

Browse files
committed
Prefer ZVAL_COPY
Instead of ZVAL_COPY_VALUE + Z_TRY_ADDREF. Also fix another leak in SplDoublyLinkedList::add(), the push case was leaking as well.
1 parent 497fadc commit 044de83

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

ext/spl/spl_dllist.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static void spl_ptr_llist_unshift(spl_ptr_llist *llist, zval *data) /* {{{ */
168168

169169
elem->prev = NULL;
170170
elem->next = llist->head;
171-
ZVAL_COPY_VALUE(&elem->data, data);
171+
ZVAL_COPY(&elem->data, data);
172172
SPL_LLIST_RC(elem) = 1;
173173

174174
if (llist->head) {
@@ -179,8 +179,6 @@ static void spl_ptr_llist_unshift(spl_ptr_llist *llist, zval *data) /* {{{ */
179179

180180
llist->head = elem;
181181
llist->count++;
182-
183-
Z_TRY_ADDREF(elem->data);
184182
}
185183
/* }}} */
186184

@@ -190,7 +188,7 @@ static void spl_ptr_llist_push(spl_ptr_llist *llist, zval *data) /* {{{ */
190188

191189
elem->prev = llist->tail;
192190
elem->next = NULL;
193-
ZVAL_COPY_VALUE(&elem->data, data);
191+
ZVAL_COPY(&elem->data, data);
194192
SPL_LLIST_RC(elem) = 1;
195193

196194
if (llist->tail) {
@@ -201,8 +199,6 @@ static void spl_ptr_llist_push(spl_ptr_llist *llist, zval *data) /* {{{ */
201199

202200
llist->tail = elem;
203201
llist->count++;
204-
205-
Z_TRY_ADDREF(elem->data);
206202
}
207203
/* }}} */
208204

@@ -1189,7 +1185,6 @@ PHP_METHOD(SplDoublyLinkedList, add)
11891185
RETURN_THROWS();
11901186
}
11911187

1192-
Z_TRY_ADDREF_P(value);
11931188
if (index == intern->llist->count) {
11941189
/* If index is the last entry+1 then we do a push because we're not inserting before any entry */
11951190
spl_ptr_llist_push(intern->llist, value);
@@ -1200,7 +1195,7 @@ PHP_METHOD(SplDoublyLinkedList, add)
12001195
/* Get the element we want to insert before */
12011196
element = spl_ptr_llist_offset(intern->llist, index, intern->flags & SPL_DLLIST_IT_LIFO);
12021197

1203-
ZVAL_COPY_VALUE(&elem->data, value);
1198+
ZVAL_COPY(&elem->data, value);
12041199
SPL_LLIST_RC(elem) = 1;
12051200
/* connect to the neighbours */
12061201
elem->next = element;

ext/spl/tests/dllist_013.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ echo $dll->pop()."\n";
3333
// Test refcounted value
3434
$str = "foo";
3535
$str .= "bar";
36-
$dll->add(0, null);
3736
$dll->add(0, $str);
37+
$dll->add(0, $str);
38+
var_dump($dll->shift());
3839
var_dump($dll->shift());
3940

4041
?>
@@ -49,3 +50,4 @@ Exception: SplDoublyLinkedList::add(): Argument #1 ($index) is out of range
4950
2
5051
1
5152
string(6) "foobar"
53+
string(6) "foobar"

0 commit comments

Comments
 (0)