Seems like kind of a dumb place to ask, but the only one on the forum that fits :P
I was working on a function to at least temporarily fix some MXP problems, and I got it working except that there's a memory leak in the function I'm not seeing. (This is for a custom codebase, not PennMUSH or anything)
I'm aware there's probably a dozen better ways to go about doing this, but before we get into that I'd like to understand why the allocated memory isn't being freed.. Then, by all means :P
I'm also aware that that will break things for people whose clients don't support MXP, but it's only temporary, really. I could always check for support, if need be.
I was working on a function to at least temporarily fix some MXP problems, and I got it working except that there's a memory leak in the function I'm not seeing. (This is for a custom codebase, not PennMUSH or anything)
char *smash_mxp ( char *str )
{
int i, j = 0;
char *str1;
str1 = malloc(sizeof(str));
memmove(str1,str,strlen(str)+1);
for (i = 0; str1[i] != '\0';i++)
{
switch (str1[i])
{
case '<':
str[j] = '&';
str[j +1] = 'l';
str[j +2] = 't';
str[j +3] = ';';
j +=3;
break;
case '>':
str[j] = '&';
str[j +1] = 'g';
str[j +2] = 't';
str[j +3] = ';';
j +=3;
break;
case '&':
str[j] = '&';
str[j +1] = 'a';
str[j +2] = 'm';
str[j +3] = 'p';
str[j +4] = ';';
j +=4;
break;
default:
str[j] = str1[i];
break;
}
j++;
}
free(str1);
return str;
}
I'm aware there's probably a dozen better ways to go about doing this, but before we get into that I'd like to understand why the allocated memory isn't being freed.. Then, by all means :P
I'm also aware that that will break things for people whose clients don't support MXP, but it's only temporary, really. I could always check for support, if need be.