cvs: /php4/ext/hyperwave hw.c
| From: | Uwe Steinmann | Date: | Thu, 19 Aug 1999 15:03:17 +0000 |
| Subject: | cvs: /php4/ext/hyperwave hw.c | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-3586@lists.php.net to get a copy of this message | ||
steinm Thu Aug 19 11:03:17 1999 EDT
Modified files:
/php4/ext/hyperwave hw.c
Log:
- fixed several memory leaks
- fixed broken hw_cp and hw_mv functions
Index: php4/ext/hyperwave/hw.c
diff -u php4/ext/hyperwave/hw.c:1.16 php4/ext/hyperwave/hw.c:1.17
--- php4/ext/hyperwave/hw.c:1.16 Tue Aug 17 05:59:18 1999
+++ php4/ext/hyperwave/hw.c Thu Aug 19 11:03:14 1999
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: hw.c,v 1.16 1999/08/17 09:59:18 steinm Exp $ */
+/* $Id: hw.c,v 1.17 1999/08/19 15:03:14 steinm Exp $ */
#if COMPILE_DL
#include "dl/phpdl.h"
#endif
@@ -251,7 +251,7 @@
efree(objrecs);
/* Array for statistics */
- stat_arr = (zval *) emalloc(sizeof(zval));
+ MAKE_STD_ZVAL(stat_arr);
if (array_init(stat_arr) == FAILURE) {
return -1;
}
@@ -266,7 +266,6 @@
/* Add the stat array */
zend_hash_next_index_insert((*return_value)->value.ht, &stat_arr, sizeof(zval), NULL);
- /* The title array can now be freed, but I don't know how */
return 0;
}
@@ -283,9 +282,9 @@
int hasDescription = 0;
int hasKeyword = 0;
- title_arr = (zval *) emalloc(sizeof(zval));
- desc_arr = (zval *) emalloc(sizeof(zval));
- keyword_arr = (zval *) emalloc(sizeof(zval));
+ MAKE_STD_ZVAL(title_arr);
+ MAKE_STD_ZVAL(desc_arr);
+ MAKE_STD_ZVAL(keyword_arr);
if (array_init(*return_value) == FAILURE) {
(*return_value)->type = IS_STRING;
@@ -348,18 +347,25 @@
if(hasTitle) {
zend_hash_update((*return_value)->value.ht, "Title", 6, &title_arr, sizeof(zval
*), NULL);
+ } else {
+ efree(title_arr);
}
+
if(hasDescription) {
/* Add the description array, if we have one */
zend_hash_update((*return_value)->value.ht, "Description", 12, &desc_arr,
sizeof(zval *), NULL);
+ } else {
+ efree(desc_arr);
}
if(hasKeyword) {
/* Add the keyword array, if we have one */
zend_hash_update((*return_value)->value.ht, "Keyword", 8, &keyword_arr,
sizeof(zval *), NULL);
+ } else {
+ efree(keyword_arr);
}
/* All other attributes. Make a another copy first */
@@ -1664,13 +1670,12 @@
/* }}} */
void php3_hw_mvcp(INTERNAL_FUNCTION_PARAMETERS, int mvcp) {
- pval *arg1, *arg2, *arg3, *arg4, **objvIDs;
- int link, type, dest=0, from=0;
+ pval *arg1, *arg2, *arg3, *arg4;
+ int link, type, dest=0, from=0, count;
HashTable *src_arr;
hw_connection *ptr;
int collIDcount, docIDcount, i, *docIDs, *collIDs;
-fprintf(stderr, "Copy/Move %d\n", mvcp);
switch(mvcp) {
case MOVE: /* Move also has fromID */
if (ARG_COUNT(ht) != 4 || getParameters(ht, 4, &arg1, &arg2, &arg3, &arg4) ==
FAILURE)
@@ -1704,44 +1709,39 @@
}
set_swap(ptr->swap_on);
-
- if(NULL == (objvIDs = emalloc(zend_hash_num_elements(src_arr) * sizeof(pval *)))) {
- RETURN_FALSE;
- }
-
- if(getParametersArray(src_arr, zend_hash_num_elements(src_arr), objvIDs) == FAILURE) {
- RETURN_FALSE;
- }
- if(NULL == (collIDs = emalloc(zend_hash_num_elements(src_arr) * sizeof(int)))) {
- efree(objvIDs);
+ count = zend_hash_num_elements(src_arr);
+ if(NULL == (collIDs = emalloc(count * sizeof(int)))) {
RETURN_FALSE;
}
- if(NULL == (docIDs = emalloc(zend_hash_num_elements(src_arr) * sizeof(int)))) {
- efree(objvIDs);
+ if(NULL == (docIDs = emalloc(count * sizeof(int)))) {
efree(collIDs);
RETURN_FALSE;
}
collIDcount = docIDcount = 0;
- for(i=0; i<zend_hash_num_elements(src_arr); i++) {
+ zend_hash_internal_pointer_reset(src_arr);
+ for(i=0; i<count; i++) {
char *objrec;
- if(objvIDs[i]->type == IS_LONG) {
- if(0 != (ptr->lasterror = send_getobject(ptr->socket, objvIDs[i]->value.lval,
&objrec))) {
- efree(objvIDs);
+ zval *keydata, **keydataptr;
+ zend_hash_get_current_data(src_arr, (void **) &keydataptr);
+ keydata = *keydataptr;
+ if(keydata->type == IS_LONG) {
+ if(0 != (ptr->lasterror = send_getobject(ptr->socket, keydata->value.lval,
&objrec))) {
efree(collIDs);
efree(docIDs);
RETURN_FALSE;
}
if(0 == fnAttributeCompare(objrec, "DocumentType", "collection"))
- collIDs[collIDcount++] = objvIDs[i]->value.lval;
+ collIDs[collIDcount++] = keydata->value.lval;
else
- docIDs[docIDcount++] = objvIDs[i]->value.lval;
+ docIDs[docIDcount++] = keydata->value.lval;
efree(objrec);
}
+ zend_hash_move_forward(src_arr);
}
- efree(objvIDs);
+
if (0 != (ptr->lasterror = send_mvcpdocscoll(ptr->socket, docIDs, docIDcount, from, dest,
mvcp))) {
efree(collIDs);
efree(docIDs);