Click here to Skip to main content
11,634,815 members (67,459 online)

C / C++ / MFC

 
AnswerRe: Which among following statements c/c++ code is faster? Pin
ptse26-Mar-14 3:34
memberptse26-Mar-14 3:34 
GeneralRe: Which among following statements c/c++ code is faster? Pin
Richard MacCutchan26-Mar-14 5:24
protectorRichard MacCutchan26-Mar-14 5:24 
QuestionFree fails with access violation Pin
tejaswini_g24-Mar-14 16:14
membertejaswini_g24-Mar-14 16:14 
AnswerRe: Free fails with access violation Pin
Richard MacCutchan24-Mar-14 22:52
protectorRichard MacCutchan24-Mar-14 22:52 
AnswerRe: Free fails with access violation Pin
Richard Andrew x6425-Mar-14 5:59
professionalRichard Andrew x6425-Mar-14 5:59 
AnswerRe: Free fails with access violation Pin
leon de boer25-Mar-14 17:36
memberleon de boer25-Mar-14 17:36 
AnswerRe: Free fails with access violation Pin
pwasser25-Mar-14 20:13
memberpwasser25-Mar-14 20:13 
GeneralDirectShow GraphEdit missing property page options tab. PARTIALLY SOLVED - CLOSED Pin
Vaclav_Sal24-Mar-14 15:42
memberVaclav_Sal24-Mar-14 15:42 
GeneralRe: DirectShow GraphEdit missing property page options tab. Pin
Rage25-Mar-14 2:19
professionalRage25-Mar-14 2:19 
Generalx it.Re: DirectShow GraphEdit missing property page options tab.IN PROGRESS Pin
Vaclav_Sal25-Mar-14 7:29
memberVaclav_Sal25-Mar-14 7:29 
QuestionFree fails with Access violation reading location Pin
tejaswini_g24-Mar-14 13:31
membertejaswini_g24-Mar-14 13:31 
AnswerRe: Free fails with Access violation reading location Pin
Richard Andrew x6424-Mar-14 13:42
professionalRichard Andrew x6424-Mar-14 13:42 
GeneralRe: Free fails with Access violation reading location Pin
tejaswini_g24-Mar-14 15:01
membertejaswini_g24-Mar-14 15:01 
AnswerRe: Free fails with Access violation reading location Pin
leon de boer24-Mar-14 15:06
memberleon de boer24-Mar-14 15:06 
The mallocs and frees are fine in concept the issue is deeper

I suspect this is the problem

Filelist[i] = (char*)malloc((iFileSize * sizeof(char))+1);

iFileSize is initially set to zero and then passed in as a parameter to FileCountInDir which I guess is supposed to fill it in.

But I find it really strange because that function is counting the directory entries from it's function name.

Really the string space allocation should be the length of each individual directory entry name so I am not sure it should be a single value.

For example a file "fred.bmp" should allocate 9 bytes (8+asciiz 0) while "afred.bmp" should allocate 10 bytes (9+asciiz 0)

I fail to see how you are allocating them all as iFileSize unless that is the largest filename in the directory.

And that leads to the answer for your fail that iFilesize must be coming back from FileCountInDir as -1 and that means you are allocating -1+1 = 0 bytes of memory which will fail in malloc returning NULL.

Hence Filelist[i] would indeed be carrying NULL

You can put protection to stop the error by doing this

if (FileList[i] != 0) free (Filelist[i]);

But as discussed I think you have serious issues with iFileSize
GeneralRe: Free fails with Access violation reading location Pin
pwasser24-Mar-14 15:25
memberpwasser24-Mar-14 15:25 
GeneralRe: Free fails with Access violation reading location Pin
pwasser24-Mar-14 15:59
memberpwasser24-Mar-14 15:59 
QuestionRe: Free fails with Access violation reading location Pin
pwasser24-Mar-14 15:17
memberpwasser24-Mar-14 15:17 
AnswerRe: Free fails with Access violation reading location Pin
tejaswini_g24-Mar-14 15:39
membertejaswini_g24-Mar-14 15:39 
AnswerRe: Free fails with Access violation reading location Pin
pwasser24-Mar-14 16:01
memberpwasser24-Mar-14 16:01 
GeneralRe: Free fails with Access violation reading location Pin
tejaswini_g24-Mar-14 16:11
membertejaswini_g24-Mar-14 16:11 
QuestionHow do you define flags? Pin
Dusan Paulovic24-Mar-14 9:48
memberDusan Paulovic24-Mar-14 9:48 
AnswerRe: How do you define flags? Pin
Richard MacCutchan24-Mar-14 11:11
protectorRichard MacCutchan24-Mar-14 11:11 
AnswerRe: How do you define flags? Pin
Albert Holguin25-Mar-14 4:48
professionalAlbert Holguin25-Mar-14 4:48 
QuestionHow do I using WH_CALLWNDPROC and PT_TOUCH to get the global touch event Pin
cedricvictor24-Mar-14 3:48
membercedricvictor24-Mar-14 3:48 
Questionvisual studio 6.0 Enterprise edition License Pin
KrishnaRayalu_Talisetti24-Mar-14 0:47
memberKrishnaRayalu_Talisetti24-Mar-14 0:47 
AnswerRe: visual studio 6.0 Enterprise edition License Pin
Jochen Arndt24-Mar-14 1:02
professionalJochen Arndt24-Mar-14 1:02 
AnswerRe: visual studio 6.0 Enterprise edition License Pin
DavidCrow24-Mar-14 4:51
memberDavidCrow24-Mar-14 4:51 
QuestionBuilding / compiling DirectShow "empty DLL". Pin
Vaclav_Sal23-Mar-14 5:51
memberVaclav_Sal23-Mar-14 5:51 
SuggestionRe: Building / compiling DirectShow "empty DLL". Pin
Richard MacCutchan23-Mar-14 22:59
protectorRichard MacCutchan23-Mar-14 22:59 
QuestionWin CE program, SetFong() not work Pin
econy21-Mar-14 7:21
memberecony21-Mar-14 7:21 
AnswerRe: Win CE program, SetFong() not work Pin
Rage25-Mar-14 2:15
professionalRage25-Mar-14 2:15 
AnswerRe: Win CE program, SetFong() not work Pin
Rage25-Mar-14 2:17
professionalRage25-Mar-14 2:17 
GeneralRe: Win CE program, SetFong() not work Pin
econy25-Mar-14 3:32
memberecony25-Mar-14 3:32 
QuestionWidth of dropdown list window Pin
bokideclan21-Mar-14 2:33
memberbokideclan21-Mar-14 2:33 
QuestionVery weird change font problem Pin
econy20-Mar-14 8:18
memberecony20-Mar-14 8:18 
QuestionRe: Very weird change font problem Pin
Randor 20-Mar-14 8:43
professional Randor 20-Mar-14 8:43 
AnswerRe: Very weird change font problem Pin
econy20-Mar-14 9:00
memberecony20-Mar-14 9:00 
AnswerRe: Very weird change font problem Pin
Randor 20-Mar-14 10:22
professional Randor 20-Mar-14 10:22 
GeneralRe: Very weird change font problem Pin
econy20-Mar-14 10:33
memberecony20-Mar-14 10:33 
AnswerRe: Very weird change font problem Pin
Randor 20-Mar-14 10:51
professional Randor 20-Mar-14 10:51 
GeneralRe: Very weird change font problem Pin
econy20-Mar-14 13:20
memberecony20-Mar-14 13:20 
QuestionSetfont() not work Pin
econy20-Mar-14 5:38
memberecony20-Mar-14 5:38 
AnswerRe: Setfont() not work Pin
Randor 20-Mar-14 8:35
professional Randor 20-Mar-14 8:35 
GeneralRe: Setfont() not work Pin
econy20-Mar-14 8:42
memberecony20-Mar-14 8:42 
QuestionCEdit GetRect() question Pin
econy20-Mar-14 4:02
memberecony20-Mar-14 4:02 
AnswerRe: CEdit GetRect() question Pin
econy20-Mar-14 6:38
memberecony20-Mar-14 6:38 
QuestionCDatabase::ExecuteSQL Pin
Fawaz Ajani19-Mar-14 22:33
memberFawaz Ajani19-Mar-14 22:33 
SuggestionRe: CDatabase::ExecuteSQL Pin
Richard MacCutchan19-Mar-14 23:22
protectorRichard MacCutchan19-Mar-14 23:22 
GeneralRe: CDatabase::ExecuteSQL Pin
Fawaz Ajani20-Mar-14 1:55
memberFawaz Ajani20-Mar-14 1:55 
GeneralRe: CDatabase::ExecuteSQL Pin
Richard MacCutchan20-Mar-14 2:33
protectorRichard MacCutchan20-Mar-14 2:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.150728.1 | Last Updated 29 Jul 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid