Click here to Skip to main content
15,914,215 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: DirectSound Buffer->Lock Error Pin
Rage26-May-03 2:16
professionalRage26-May-03 2:16 
GeneralRe: DirectSound Buffer->Lock Error Pin
Miepmuts26-May-03 2:54
Miepmuts26-May-03 2:54 
GeneralRe: DirectSound Buffer->Lock Error Pin
Rage26-May-03 3:44
professionalRage26-May-03 3:44 
GeneralRe: DirectSound Buffer->Lock Error Pin
Miepmuts26-May-03 4:15
Miepmuts26-May-03 4:15 
GeneralGCC with MCVC IDE Pin
Andrew Walker26-May-03 1:24
Andrew Walker26-May-03 1:24 
GeneralRe: GCC with MCVC IDE Pin
tareqsiraj26-May-03 9:42
tareqsiraj26-May-03 9:42 
GeneralVC 5 <-> VC6 Pin
JensB26-May-03 0:04
JensB26-May-03 0:04 
GeneralScope Error Pin
Paul Hooper25-May-03 23:45
Paul Hooper25-May-03 23:45 
I just spent the best part of today finding a nasty little bug and thought I might "share" with you.

We had some code that basically went

{<br />
   CPen apen;<br />
   apen.CreatePen(...);<br />
   dc->SelectObject(&apen);<br />
<br />
   //Do lots of work with dc<br />
<br />
   dc->SelectStockObject(BLACK_PEN);  //Select apen out so it can clean up<br />
}


Last version, the code was changed to something like

{<br />
   if (option)<br />
   {<br />
      CPen apen;<br />
      apen.CreatePen(...);<br />
      dc->SelectObject(&apen);<br />
<br />
      //Do lots of work with dc<br />
   }<br />
   else<br />
   {<br />
      CPen bpen;<br />
      bpen.CreatePen(...);<br />
      dc->SelectObject(&bpen);<br />
<br />
      //Do lots of work with dc<br />
   }<br />
   dc->SelectStockObject(BLACK_PEN);  //Select pens out so they can clean up<br />
} 


I am sure you can see the error... apen and bpen are now being destroyed before selected out. Resource leak.

Running this code on Win2000/XP is fine because they clean up the mess. Running on 95,98,ME caused massive resource leaks (obviously!) The error is obvious when simplified as above but it was not the least bit obvious in the production code.

It's always the simple things that bite you!

Paul Hooper

If you spend your whole life looking over your shoulder, they will get you from the front instead.
GeneralRe: Scope Error Pin
John R. Shaw26-May-03 9:51
John R. Shaw26-May-03 9:51 
GeneralRe: Scope Error Pin
John R. Shaw26-May-03 10:04
John R. Shaw26-May-03 10:04 
GeneralCommunication problem between dialog window and frame window Pin
chen25-May-03 23:38
chen25-May-03 23:38 
GeneralRe: Communication problem between dialog window and frame window Pin
Rage25-May-03 23:52
professionalRage25-May-03 23:52 
QuestionHow Do I Drag&amp;Drop an ActiveX Control Pin
ccdai25-May-03 23:11
ccdai25-May-03 23:11 
GeneralParsing in C Pin
Rickard Andersson2025-May-03 22:57
Rickard Andersson2025-May-03 22:57 
GeneralRe: Parsing in C Pin
jhwurmbach25-May-03 23:26
jhwurmbach25-May-03 23:26 
GeneralRe: Parsing in C Pin
Rickard Andersson2026-May-03 0:24
Rickard Andersson2026-May-03 0:24 
GeneralRe: Parsing in C Pin
John R. Shaw26-May-03 10:13
John R. Shaw26-May-03 10:13 
GeneralRe: Parsing in C Pin
Paul Hooper25-May-03 23:29
Paul Hooper25-May-03 23:29 
GeneralRe: Parsing in C Pin
Rickard Andersson2026-May-03 0:30
Rickard Andersson2026-May-03 0:30 
GeneralRe: Parsing in C Pin
Paul Hooper26-May-03 1:51
Paul Hooper26-May-03 1:51 
GeneralRe: Parsing in C Pin
Rage25-May-03 23:46
professionalRage25-May-03 23:46 
GeneralRe: Parsing in C Pin
Rickard Andersson2026-May-03 0:32
Rickard Andersson2026-May-03 0:32 
GeneralRe: Parsing in C Pin
Ryan Binns26-May-03 1:46
Ryan Binns26-May-03 1:46 
GeneralRe: Parsing in C Pin
jhwurmbach26-May-03 2:19
jhwurmbach26-May-03 2:19 
GeneralRe: Parsing in C Pin
Ryan Binns26-May-03 2:22
Ryan Binns26-May-03 2:22 

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.