Results 1 to 2 of 2

Thread: Memory Leak

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2002
    Posts
    24

    Memory Leak

    Would this cause a memory leak or cause any other problems?

    Code:
    char *TestDecrypt(char *pText)
    { 
    	char pText2[1024];
    	strcpy(pText2, pText);
    	for(unsigned int i=0; i<strlen(pText); i++) 
    	{
    		pText2[i]--;	
    	}
    	char *strTextReturn = pText2;
    	return strTextReturn;
    }

  2. #2
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    You're returning a local variable which will sooner or later become trashed.

    try passing TWO char arrays, one to keep the new stuff:
    Code:
    char *TestDecrypt(char *dest,char *pText)
    { 
    	char pText2[1024];
    	strcpy(pText2, pText);
    	for(char *buf=dest,unsigned int i=0; i<strlen(pText); i++,buf++) 
    	{
    		*buf=--pText2[i];	
    	}
    	
    	return dest;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width