Jump to content

Memory issues


CurlyMo

Recommended Posts

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);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.