Sybase-CT memory leaks and crashes

From: Date: Fri, 19 Nov 1999 00:58:07 +0000
Subject: Sybase-CT memory leaks and crashes
Groups: php.version4 
Request: Send a blank email to php-version4+get-6466@lists.php.net to get a copy of this message
Having tried both beta2 and beta3 out on development boxes for the site I administer, I noticed massive (150mb+) error logs being generated by Apache regarding small (2->4byte) memory leaks, and a large number of segfaults and overruns by various parts of Zend. On a hunch, I dug out the sybase-ct ext code and rewrote part of the php_sybase_fetch_hash function, and much to my surprise (I follow a lot of hunches, but they only rarely turn out to be right first time) it appears to have solved the problem entirely. I'm not a frequent programmer in the php4 source, so I don't pretend that this is necessarily the best way, or even a good way to solve it :) nor do I usually follow this list, however I was unable to find any other way of submitting a fix without a cvs uid/pwd. The function now reads: ----------- static void php_sybase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS) { pval *sybase_result_index; sybase_result *result; int i; int should_copy; pval *tmp; PLS_FETCH(); if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &sybase_result_index)==FAILURE) { WRONG_PARAM_COUNT; } ZEND_FETCH_RESOURCE(result, sybase_result *, &sybase_result_index, -1, "Sybase result", sybase_globals.le_result); if (result->cur_row >= result->num_rows) { RETURN_FALSE; } if (array_init(return_value)==FAILURE) { RETURN_FALSE; } for (i=0; i<result->num_fields; i++) { char *data; int data_len; tmp = &result->data[result->cur_row][i]; if (PG(magic_quotes_runtime)) { data = php_addslashes(tmp->value.str.val,tmp->value.str.len,&data_len,0); should_copy = 0; } else { data = tmp->value.str.val; data_len = tmp->value.str.len; should_copy = 1; } add_index_stringl(return_value,i,data,data_len,should_copy); should_copy = 1; add_assoc_stringl(return_value,result->fields[i].name,data,data_len,should_copy); /* ---- Old code here ---- tmp = (pval *) emalloc(sizeof(pval)); *tmp = result->data[result->cur_row][i]; INIT_PZVAL(tmp); pval_copy_constructor(tmp); if (PG(magic_quotes_runtime) && tmp->type == IS_STRING) { tmp->value.str.val = php_addslashes(tmp->value.str.val,tmp->value.str.len,&tmp->value.str.len,1); } zend_hash_index_update(return_value->value.ht, i, (void *) &tmp, sizeof(pval *), NULL); zend_hash_update(return_value->value.ht, result->fields[i].name, strlen(result->fields[i].name)+1, (void *) &tmp, sizeof(pval *), NULL); */ } result->cur_row++; } ---------- Richard Clark, Iguana Information Services. richard@iguana.co.nz

« previous php.version4 (#6466) next »