Click here to Skip to main content
16,016,814 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Question[Solved] Memory leak in producer-consumer program Pin
noislude25-Feb-13 7:30
noislude25-Feb-13 7:30 
AnswerRe: Memory leak in producer-consumer program Pin
Richard Andrew x6425-Feb-13 10:08
professionalRichard Andrew x6425-Feb-13 10:08 
GeneralRe: Memory leak in producer-consumer program Pin
noislude25-Feb-13 10:23
noislude25-Feb-13 10:23 
GeneralRe: Memory leak in producer-consumer program Pin
Richard Andrew x6425-Feb-13 10:33
professionalRichard Andrew x6425-Feb-13 10:33 
GeneralRe: Memory leak in producer-consumer program Pin
noislude25-Feb-13 10:42
noislude25-Feb-13 10:42 
QuestionRe: Memory leak in producer-consumer program Pin
David Crow25-Feb-13 13:28
David Crow25-Feb-13 13:28 
AnswerRe: Memory leak in producer-consumer program Pin
noislude25-Feb-13 13:33
noislude25-Feb-13 13:33 
GeneralRe: Memory leak in producer-consumer program Pin
Stefan_Lang26-Feb-13 3:29
Stefan_Lang26-Feb-13 3:29 
The error output points at the function consumer, and the program output indicates the state before hitting the error: You're writing to an array index of -1 in this line:
C++
buffer[buffindex] = '\0';

, after decreasing buffindex from 0 to -1 in this line:
C++
printf("Consume: %d\n", buffindex--);

Suggested fix: change
C++
if(buffindex == -1)

to
C++
if(buffindex == 0)

, or better yet:
C++
if(buffindex <= 0)

(in case you accidentally decrease buffindex multiple times; your current code doesn't seem to be able to achieve that, but code changes...)

The leak information may go away after fixing the error, it may just be a consequence of the abnormal error condition. if not, please come back with your new results.
GeneralRe: Memory leak in producer-consumer program Pin
noislude26-Feb-13 8:07
noislude26-Feb-13 8:07 
GeneralRe: Memory leak in producer-consumer program Pin
Stefan_Lang26-Feb-13 22:21
Stefan_Lang26-Feb-13 22:21 
GeneralRe: Memory leak in producer-consumer program Pin
noislude26-Feb-13 22:27
noislude26-Feb-13 22:27 
GeneralRe: Memory leak in producer-consumer program Pin
Stefan_Lang26-Feb-13 23:01
Stefan_Lang26-Feb-13 23:01 
SuggestionRe: Memory leak in producer-consumer program Pin
noislude27-Feb-13 9:47
noislude27-Feb-13 9:47 
AnswerRe: Memory leak in producer-consumer program Pin
Vaclav_25-Feb-13 17:45
Vaclav_25-Feb-13 17:45 
QuestionWhat is the MFC future Pin
Arris7425-Feb-13 7:06
Arris7425-Feb-13 7:06 
AnswerRe: What is the MFC future Pin
Vaclav_25-Feb-13 9:46
Vaclav_25-Feb-13 9:46 
GeneralRe: What is the MFC future Pin
Richard Andrew x6425-Feb-13 10:07
professionalRichard Andrew x6425-Feb-13 10:07 
AnswerRe: What is the MFC future Pin
yu-jian25-Feb-13 21:30
yu-jian25-Feb-13 21:30 
GeneralRe: What is the MFC future Pin
Pete O'Hanlon26-Feb-13 3:30
mvePete O'Hanlon26-Feb-13 3:30 
AnswerRe: What is the MFC future Pin
Stefan_Lang26-Feb-13 3:16
Stefan_Lang26-Feb-13 3:16 
GeneralRe: What is the MFC future Pin
yu-jian26-Feb-13 17:44
yu-jian26-Feb-13 17:44 
AnswerRe: What is the MFC future Pin
_AnsHUMAN_ 27-Feb-13 1:42
_AnsHUMAN_ 27-Feb-13 1:42 
AnswerRe: What is the MFC future Pin
Joe Woodbury4-Mar-13 12:00
professionalJoe Woodbury4-Mar-13 12:00 
QuestionWere is a source of "sal.h" header file? Pin
Vaclav_25-Feb-13 5:19
Vaclav_25-Feb-13 5:19 
AnswerRe: Were is a source of "sal.h" header file? Pin
Richard MacCutchan25-Feb-13 5:44
mveRichard MacCutchan25-Feb-13 5:44 

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

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