Skip to content

Commit 6890f98

Browse files
committed
Fix leak, and avoid initialization problems where retval is re-used
within a function.
1 parent e737d2c commit 6890f98

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

main/user_streams.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,10 @@ static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
464464
}
465465
zval_ptr_dtor(&zcount);
466466

467-
if (retval)
467+
if (retval) {
468468
zval_ptr_dtor(&retval);
469+
retval = NULL;
470+
}
469471

470472
/* since the user stream has no way of setting the eof flag directly, we need to ask it if we hit eof */
471473

@@ -487,6 +489,11 @@ static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count
487489
stream->eof = 1;
488490
}
489491

492+
if (retval) {
493+
zval_ptr_dtor(&retval);
494+
retval = NULL;
495+
}
496+
490497
return didread;
491498
}
492499

@@ -586,8 +593,10 @@ static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, o
586593
ret = -1;
587594
}
588595

589-
if (retval)
596+
if (retval) {
590597
zval_ptr_dtor(&retval);
598+
retval = NULL;
599+
}
591600

592601
/* now determine where we are */
593602
ZVAL_STRINGL(&func_name, USERSTREAM_TELL, sizeof(USERSTREAM_TELL)-1, 0);
@@ -603,10 +612,10 @@ static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, o
603612
else
604613
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_TELL " is not implemented!",
605614
us->wrapper->classname);
606-
615+
607616
if (retval)
608617
zval_ptr_dtor(&retval);
609-
618+
610619
return 0;
611620
}
612621

0 commit comments

Comments
 (0)