String Memory problem

hi, i am using client server program with multi thread, I use the file concept and pointer. my function is
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
void CGlobals::ReadDataFromFile(char * pTemplateName, char * pUserId, std::string * pReadData)
{
	FILE               * fpFile;
	char               * pData;
	char               * pFileName;
	string               sData;
	string               sFileName;
	long                  iLen;
	long                 dwLength;
	long                 dwResult;
cout<<" Enter into Read Deta Frome File"<<endl;
	if(strcmp(pUserId, "NULL"))
	{
		pFileName = new char[strlen(pTemplateName) + strlen(pUserId) + 1];
		iLen = sprintf(pFileName, "%s_%s",
						pTemplateName,
						pUserId);
	}
	else
	{
		pFileName = new char[strlen(pTemplateName)];
		iLen = sprintf(pFileName, "%s", pTemplateName);
	}
	cout<<" Compare finish into Read Deta Frome File"<<endl;
	pFileName[iLen] = '\0';
	fpFile = fopen(pFileName,"r");

	if(!fpFile)
	{
		pReadData->assign("NONE");
		fpFile = fopen(pFileName,"w");
		fclose(fpFile);
		delete [] pFileName;
		pFileName = NULL;	
		return;
	}
	cout<<" file open finish into Read Deta Frome File"<<endl;
	if(fseek(fpFile,0,SEEK_END))
	{
		pReadData->assign("NONE");
		delete [] pData;
		pData = NULL;
		fclose(fpFile);
		return;	
	}
cout<<" file seek   finish into Read Deta Frome File"<<endl;
	dwLength = (long) ftell(fpFile);
	fclose(fpFile);
	
	fpFile = fopen(pFileName,"r");
	iLen = (long) dwLength;
	pData = new char [iLen + 1];
	memset(pData,0,strlen(pData));
	dwResult = fread (pData,1,iLen,fpFile);
	pData[iLen] = '\0';
cout<<" file read   finish into Read Deta Frome File"<<endl;

	
	if(dwResult != dwLength)
	{
		std::cout<<"File Reading Error"<<endl<<pData<<endl;
		pReadData->assign("NONE");
	}
	else if(!dwResult)
		pReadData->assign("NONE");
	else
		{pReadData->assign(pData);}
cout<<" file close   finish into Read Deta Frome File"<<endl;
		fclose(fpFile);
cout<<" file close   finish into Read Deta Frome File"<<endl;
	delete [] pData;
	pData = NULL;
	delete [] pFileName;
	pFileName = NULL;
	//delete pReadData;
	return;
}

The above function retrieve whole file.
my problem is if i login another user then {pReadData->assign(pData);} is error occur

Error Details:
malloc.c:2451: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.

how to solve this problem


Note: file size is different.
Last edited on
Topic archived. No new replies allowed.