iliaa Tue Apr 20 20:11:30 2004 EDT Modified files: (Branch: PHP_4_3) /php-src/ext/sysvshm sysvshm.c Log: MFH: Fixed possible memory leaks. Prevent shm_attach() from destroying non-shm resources. http://cvs.php.net/diff.php/php-src/ext/sysvshm/sysvshm.c?r1=1.56.8.3&r2=1.56.8.4&ty=u Index: php-src/ext/sysvshm/sysvshm.c diff -u php-src/ext/sysvshm/sysvshm.c:1.56.8.3 php-src/ext/sysvshm/sysvshm.c:1.56.8.4 --- php-src/ext/sysvshm/sysvshm.c:1.56.8.3 Thu Aug 28 16:01:32 2003 +++ php-src/ext/sysvshm/sysvshm.c Tue Apr 20 20:11:30 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: sysvshm.c,v 1.56.8.3 2003/08/28 20:01:32 iliaa Exp $ */ +/* $Id: sysvshm.c,v 1.56.8.4 2004/04/21 00:11:30 iliaa Exp $ */ /* This has been built and tested on Linux 2.2.14 * @@ -127,25 +127,25 @@ shm_key = Z_LVAL_PP(arg_key); } - if((shm_list_ptr = (sysvshm_shm *) emalloc(sizeof(sysvshm_shm)))==NULL) { - php_error(E_WARNING, "shm_attach() failed for key 0x%x: cannot allocate internal listelement", shm_key); - RETURN_FALSE; - } + shm_list_ptr = (sysvshm_shm *) emalloc(sizeof(sysvshm_shm)); /* get the id from a specified key or create new shared memory */ if((shm_id=shmget(shm_key,0,0))<0) { if(shm_size<sizeof(sysvshm_chunk_head)) { php_error(E_WARNING, "shm_attach() failed for key 0x%x: memorysize too small", shm_key); + efree(shm_list_ptr); RETURN_FALSE; } if((shm_id=shmget(shm_key,shm_size,shm_flag|IPC_CREAT|IPC_EXCL))<0) { php_error(E_WARNING, "shmget() failed for key 0x%x: %s", shm_key, strerror(errno)); + efree(shm_list_ptr); RETURN_FALSE; } } if((shm_ptr = shmat(shm_id,NULL,0))==(void *)-1) { php_error(E_WARNING, "shmget() failed for key 0x%x: %s", shm_key, strerror(errno)); + efree(shm_list_ptr); RETURN_FALSE; } @@ -172,18 +172,22 @@ Disconnects from shared memory segment */ PHP_FUNCTION(shm_detach) { - pval **arg_id; - long id; + zval **arg_id; + int type; + sysvshm_shm *shm_list_ptr; - if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg_id) == FAILURE) { + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg_id) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long_ex(arg_id); - - id = Z_LVAL_PP(arg_id); + shm_list_ptr = (sysvshm_shm *) zend_list_find(Z_LVAL_PP(arg_id), &type); + if (!shm_list_ptr || type != php_sysvshm.le_shm) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "The parameter is not a valid shm_indentifier"); + RETURN_FALSE; + } - zend_list_delete(id); + zend_list_delete(Z_LVAL_PP(arg_id)); RETURN_TRUE; }
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php