|
-
August 26th, 2002, 11:01 AM
#1
using free function after malloc
Have written a function as follows....I am getting an error when I try to free the allocated memory through malloc...
Have put in a commment against the Free functions that are returning an error
Please HELP!
CString getLogFilename()
{
int x,temp;
char *yyyy = (char *)malloc(4);
char *mm = (char *)malloc(2);
char *dd = (char *)malloc(2);
char *zeroCat = (char *)malloc(2);
strcpy(zeroCat,"0");
CTime t = CTime::GetCurrentTime();
CString filename;
char appendDate[8];
/* get the year in yyyy format*/
x = t.GetYear();
_itoa(x,yyyy,10);
/* get the Month in mm format */
x = t.GetMonth();
_itoa(x,mm,10);
if(strlen(mm) == 1){
strcat(zeroCat,mm);
strcpy(mm,zeroCat);
strcpy(zeroCat,"0");
}
/* get the Day in dd format */
x = t.GetDay();
_itoa(x,dd,10);
if(strlen(dd) == 1){
strcat(zeroCat,dd);
strcpy(dd,zeroCat);
}
strcpy(appendDate,yyyy);
strcat(appendDate,mm);
strcat(appendDate,dd);
filename = appendDate;
free(yyyy); /*Error */
free(mm); /*Error */
free(dd); /*Error */
free(zeroCat); /*Error */
free(appendDate); /*Error */
return filename;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|