Jump to content


Photo

Memory issues


  • Please log in to reply
No replies to this topic

#1 CurlyMo

CurlyMo
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 01 July 2005 - 02:07 PM

I have a bit of a problem here. I'm fairly new in programming in c but i can write some simple programs.


What i wrote is a program that simply encodes my php scripts en decodes them again with the right password. This worked fine when i ran the code just as a c executeable.
Now i made a php function of this c code. The only problem is, that when i keep executing my php script the memory keeps remembering my previous values:

The code i run throught zend_eval_string (after it's decoded) is:

?><?PHP
echo 'good';
?>

the output of this script is for the first time:

good

the second time:

good?>good

the third time:

good?>good?>good

and so on.


So the question i have, how can i succesfully fill the memory for just ones and free it after executing my script.



The important pieces of code:

char * decrypt(char *content)
{
struct hashdata h[NOOFKEY];
FILE *df1;
char c, ch, buf[BUFSIZ], line[BUFSIZ];
int i,x;
char * rStr = (char *) malloc(strlen(content));
x = 0;
strcat(line,"?>");
for (i=0;i<NOOFKEY;i++)
    readEncryptKey(&h[i]);

strncpy(&c,content+x,1);
while(c != '\0')
   {
   x++;
   for(i=0;i<NOOFKEY;i++)
      c = hash(&h[i],c);
   sprintf(buf,"%c",c);
   strncpy(&c,content+x,1);
   strcat(line,buf);
   }
strcpy(rStr,line);
return rStr;
free(rStr);
}

/* implement function that is meant to be made available to PHP */
ZEND_FUNCTION(meradecode)
{
char *parameter;
int parameter_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &parameter, &parameter_len) == FAILURE)
    return;

zend_eval_string(decrypt(parameter),NULL,"Meraweb Encoder");
/*RETURN_STRING(decrypt(parameter),0);*/
free(parameter);
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users