cvs: php4 /ext/standard file.c

From: Date: Sun, 14 Jan 2001 14:11:38 +0000
Subject: cvs: php4 /ext/standard file.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-3608@lists.php.net to get a copy of this message
thies Sun Jan 14 06:11:38 2001 EDT Modified files: /php4/ext/standard file.c Log: fixed readfile() fd-leak. guys, always remember that every function that *generates output* could cause a bailout if ignore_user_abort is set to false (and the user _aborts_ the connection). in this case a longjump will be performed and our function (in this case readfile) will have no chance to clean-up. having said that it's a good idea to register all opened files using REGISTER_RESOURCE - that way the engine will make sure they get closed on request end. Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.134 php4/ext/standard/file.c:1.135 --- php4/ext/standard/file.c:1.134 Sat Jan 13 15:49:44 2001 +++ php4/ext/standard/file.c Sun Jan 14 06:11:38 2001 @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.134 2001/01/13 23:49:44 zeev Exp $ */ +/* $Id: file.c,v 1.135 2001/01/14 14:11:38 thies Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -1395,6 +1395,7 @@ int size=0; int use_include_path=0; int issock=0, socketd=0; + int rsrc_id; /* check args */ switch (ARG_COUNT(ht)) { @@ -1429,14 +1430,21 @@ } RETURN_FALSE; } - if (php_header()) { - size = php_passthru_fd(socketd, fp, issock); - } + if (issock) { - SOCK_FCLOSE(socketd); + int *sock=emalloc(sizeof(int)); + *sock = socketd; + rsrc_id = ZEND_REGISTER_RESOURCE(NULL,sock,php_file_le_socket()); } else { - fclose(fp); + rsrc_id = ZEND_REGISTER_RESOURCE(NULL,fp,php_file_le_fopen()); } + + if (php_header()) { + size = php_passthru_fd(socketd, fp, issock); + } + + zend_list_delete(rsrc_id); + RETURN_LONG(size); }

« previous php.cvs (#3608) next »