Home
%3CLINGO-SUB%20id%3D%22lingo-sub-723605%22%20slang%3D%22en-US%22%3EThe%20Case%20of%20the%20Frozen%20Clock%20Gadget%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-723605%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20TechNet%20on%20Oct%2015%2C%202007%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20Besides%20Aero%20Glass%2C%20one%20of%20the%20most%20visible%20features%20of%20Windows%20Vista%20is%20the%20Sidebar%20with%20its%20set%20of%20default%20Gadgets%2C%20like%20the%20clock%2C%20RSS%20feed%2C%20and%20photo%20viewer.%20The%20convenience%20of%20having%20frequently-accessed%20information%20on%20the%20desktop%20and%20the%20ease%20of%20their%20development%20has%20led%20to%20the%20availability%20of%20literally%20thousands%20of%20third-party%20Gadgets%20through%20sites%20like%20the%20%3CA%20class%3D%22%22%20href%3D%22http%3A%2F%2Fvista.gallery.microsoft.com%2Fvista%2FSideBar.aspx%3Fmkt%3Den-us%22%20mce_href%3D%22http%3A%2F%2Fvista.gallery.microsoft.com%2Fvista%2FSideBar.aspx%3Fmkt%3Den-us%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EWindows%20Vista%20Gadget%20Gallery%20%3C%2FA%3E%3C%2FFONT%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E.%20I%E2%80%99ve%20downloaded%20and%20installed%20a%20few%20out%20of%20curiosity%2C%20and%20in%20some%20cases%20kept%20them%20in%20my%20Sidebar%E2%80%99s%20standard%20configuration%2C%20and%20never%20experienced%20a%20problem.%20%3CSPAN%20style%3D%22mso-spacerun%3A%20yes%22%3E%20%3C%2FSPAN%3E%20A%20few%20days%20after%20installing%20a%20batch%20of%20new%20Gadgets%2C%20however%2C%20I%20noticed%20that%20a%20third-party%20clock%20Gadget%20had%20stopped%20updating%2C%20and%20so%20I%20set%20out%20to%20investigate.%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20My%20system%20was%20otherwise%20functioning%20normally%2C%20so%20my%20first%20step%20was%20to%20see%20if%20something%20was%20amiss%20with%20the%20Sidebar%E2%80%99s%20configuration.%20I%20right-clicked%20on%20the%20Sidebar%20screen%20area%20and%20selected%20the%20Properties%20menu%20item%2C%20but%20instead%20of%20displaying%20the%20Sidebar%20configuration%20dialog%2C%20the%20Sidebar%20crashed%3A%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CIMG%20height%3D%22291%22%20mce_src%3D%22http%3A%2F%2Fblogs.technet.com%2Fphotos%2Fmarkrussinovich%2Fimages%2F2178594%2Foriginal.aspx%22%20original-url%3D%22http%3A%2F%2Fblogs.technet.com%2Fphotos%2Fmarkrussinovich%2Fimages%2F2178594%2Foriginal.aspx%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F120992iEB70A1509CA2F74D%22%20style%3D%22WIDTH%3A%20484px%3B%20HEIGHT%3A%20291px%22%20width%3D%22484%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20Gadgets%20run%20inside%20of%20shared%20Sidebar%20processes%2C%20so%20my%20first%20thought%20was%20that%20memory%20corruption%20in%20the%20Sidebar%20process%20had%20caused%20the%20clock%20to%20stop%20and%20subsequent%20crash%2C%20and%20verifying%20that%20theory%20required%20that%20I%20analyze%20the%20crash.%20The%20Windows%20Error%20Reporting%20(WER)%20service%20creates%20a%20crash-dump%20file%2C%20which%20is%20the%20saved%20state%20of%20a%20faulting%20process%2C%20in%20case%20you%20agree%20to%20send%20information%20to%20Microsoft%20about%20a%20problem.%20I%20clicked%20open%20the%20View%20Details%20area%20to%20see%20where%20Windows%20had%20saved%20the%20dump%3A%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20%3CIMG%20height%3D%22375%22%20mce_src%3D%22http%3A%2F%2Fblogs.technet.com%2Fphotos%2Fmarkrussinovich%2Fimages%2F2178596%2Foriginal.aspx%22%20original-url%3D%22http%3A%2F%2Fblogs.technet.com%2Fphotos%2Fmarkrussinovich%2Fimages%2F2178596%2Foriginal.aspx%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F120993i987318845BCBB51D%22%20style%3D%22WIDTH%3A%20440px%3B%20HEIGHT%3A%20375px%22%20width%3D%22440%22%20%2F%3E%20%3C%2FFONT%3E%3C%2FP%3E%3CSPAN%20style%3D%22mso-no-proof%3A%20yes%22%3E%20%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3EThe%20last%20path%20displayed%20by%20the%20dialog%2C%20WERD8EE.tmp.mdmp%2C%20is%20a%20dump%20file%2C%20so%20I%20launched%20the%20%3CA%20class%3D%22%22%20href%3D%22http%3A%2F%2Fwww.microsoft.com%2Fwhdc%2FDevTools%2FDebugging%2Fdefault.mspx%22%20mce_href%3D%22http%3A%2F%2Fwww.microsoft.com%2Fwhdc%2FDevTools%2FDebugging%2Fdefault.mspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EMicrosoft%20Debugging%20Tools%20for%20Windows%20Windbg%20%3C%2FA%3E%3C%2FFONT%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3Eutility%20and%20opened%20the%20file.%20When%20you%20open%20a%20dump%20file%2C%20Windbg%20automatically%20shows%20you%20the%20instruction%20that%20ultimately%20lead%20to%20the%20crash.%20In%20this%20case%2C%20it%20was%20a%20memory%20copy%20operation%20in%20Msvcrt%2C%20the%20Microsoft%20C%20Runtime%3A%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CIMG%20height%3D%2292%22%20mce_src%3D%22http%3A%2F%2Fblogs.technet.com%2Fphotos%2Fmarkrussinovich%2Fimages%2F2178598%2Foriginal.aspx%22%20original-url%3D%22http%3A%2F%2Fblogs.technet.com%2Fphotos%2Fmarkrussinovich%2Fimages%2F2178598%2Foriginal.aspx%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F120994iA0052B0681635540%22%20style%3D%22WIDTH%3A%20550px%3B%20HEIGHT%3A%2092px%22%20width%3D%22550%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CSPAN%20style%3D%22mso-no-proof%3A%20yes%22%3E%20%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20The%20right%20side%20of%20the%20line%20showing%20the%20instruction%20indicates%20that%20the%20target%20address%20of%20the%20copy%20is%200.%20When%20a%20memory%20resource%20is%20exhausted%2C%20memory-allocation%20functions%20typically%20return%20address%200%2C%20also%20known%20as%20a%20NULL%20pointer%2C%20because%20that%E2%80%99s%20an%20illegal%20address%20by%20default%20for%20a%20Windows%20process%20(an%20application%20can%20manually%20create%20read%2Fwrite%20memory%20at%20address%20zero%2C%20but%20in%20general%20it%E2%80%99s%20not%20done).%20The%20fact%20that%20Sidebar%20referenced%20address%200%20didn%E2%80%99t%20conclusively%20mean%20the%20crash%20was%20due%20to%20low-memory%20instead%20of%20corruption%2C%20but%20it%20appeared%20likely.%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20I%20next%20looked%20at%20the%20code%20that%20led%20to%20the%20crash%2C%20which%20would%20tell%20me%20if%20it%20was%20a%20Gadget%20or%20the%20Sidebar%20itself%20that%20had%20passed%20a%20NULL%20pointer%20to%20the%20C%20Runtime.%20To%20do%20so%2C%20I%20opened%20Windbg%E2%80%99s%20stack%20dialog%3A%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CIMG%20height%3D%22303%22%20mce_src%3D%22http%3A%2F%2Fblogs.technet.com%2Fphotos%2Fmarkrussinovich%2Fimages%2F2178601%2Foriginal.aspx%22%20original-url%3D%22http%3A%2F%2Fblogs.technet.com%2Fphotos%2Fmarkrussinovich%2Fimages%2F2178601%2Foriginal.aspx%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F120995i0D14989A51DBE9E9%22%20style%3D%22WIDTH%3A%20497px%3B%20HEIGHT%3A%20303px%22%20width%3D%22497%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CSPAN%20style%3D%22mso-no-proof%3A%20yes%22%3E%20%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3EI%20had%20previously%20configured%20Windbg%E2%80%99s%20symbol%20path%20to%20point%20at%20the%20%3CA%20class%3D%22%22%20href%3D%22http%3A%2F%2Fwww.microsoft.com%2Fwhdc%2Fdevtools%2Fdebugging%2Fdebugstart.mspx%22%20mce_href%3D%22http%3A%2F%2Fwww.microsoft.com%2Fwhdc%2Fdevtools%2Fdebugging%2Fdebugstart.mspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EMicrosoft%20symbol%20server%20%3C%2FA%3E%3C%2FFONT%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3Eso%20that%20Windbg%20reports%20names%20of%20internal%20functions%20in%20Windows%20images%2C%20because%20knowing%20function%20names%20can%20often%20make%20understanding%20a%20dump%20file%20easier.%20The%20functions%20listed%20in%20the%20stack%20trace%20implied%20that%20Sidebar%20was%20querying%20the%20version%20of%20a%20%E2%80%9Cpackage%E2%80%9D%20when%20it%20crashed.%20I%E2%80%99m%20not%20sure%20what%20the%20Sidebar%20calls%20a%20package%2C%20but%20the%20trace%20did%20seem%20to%20show%20that%20Sidebar%20was%20the%20culprit%2C%20not%20a%20Gadget.%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20So%20had%20Sidebar%20run%20out%20of%20memory%3F%20There%20are%20several%20types%20of%20resource%20exhaustion%20that%20can%20cause%20a%20memory%20allocation%20to%20fail.%20For%20example%2C%20the%20system%20could%20have%20run%20out%20of%20committable%20memory%2C%20the%20process%20could%20have%20consumed%20all%20the%20memory%20in%20its%20own%20address%20space%2C%20or%20an%20internal%20heap%20could%20have%20reached%20its%20maximum%20size.%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20I%20started%20by%20checking%20the%20committed%20memory%2C%20since%20that%20was%20quick.%20Total%20commitable%20memory%2C%20also%20known%20as%20the%20commit%20limit%2C%20is%20the%20sum%20of%20the%20paging%20file(s)%20and%20most%20of%20physical%20memory.%20When%20commitable%20memory%20runs%20low%2C%20Windows%20Vista%E2%80%99s%20low-resource%20watchdog%20warns%20you%20by%20presenting%20a%20list%20of%20processes%20consuming%20the%20most%20memory%20and%20gives%20you%20the%20option%20of%20terminating%20them%20to%20relieve%20the%20memory%20pressure.%20I%20hadn%E2%80%99t%20seen%20a%20warning%2C%20so%20I%20doubted%20that%20this%20was%20the%20cause%2C%20but%20opened%20%3CA%20class%3D%22%22%20href%3D%22http%3A%2F%2Fwww.microsoft.com%2Ftechnet%2Fsysinternals%2Futilities%2Fprocessexplorer.mspx%22%20mce_href%3D%22http%3A%2F%2Fwww.microsoft.com%2Ftechnet%2Fsysinternals%2Futilities%2Fprocessexplorer.mspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EProcess%20Explorer%E2%80%99s%20%3C%2FA%3ESystem%20Information%20dialog%20to%20check%20anyway%3A%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CSPAN%20style%3D%22mso-no-proof%3A%20yes%22%3E%20%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20%3CIMG%20height%3D%22130%22%20mce_src%3D%22http%3A%2F%2Fblogs.technet.com%2Fphotos%2Fmarkrussinovich%2Fimages%2F2178602%2Foriginal.aspx%22%20original-url%3D%22http%3A%2F%2Fblogs.technet.com%2Fphotos%2Fmarkrussinovich%2Fimages%2F2178602%2Foriginal.aspx%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F120996i265B7740F8992DB1%22%20style%3D%22WIDTH%3A%20191px%3B%20HEIGHT%3A%20130px%22%20width%3D%22191%22%20%2F%3E%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20As%20I%20suspected%2C%20there%20was%20plenty%20of%20available%20Committable%20memory.%20I%20next%20looked%20at%20Sidebar%E2%80%99s%20virtual%20memory%20usage.%20Memory%20leaks%20are%20caused%20when%20a%20process%20allocates%20virtual%20memory%2C%20stores%20some%20data%20in%20it%2C%20uses%20the%20data%2C%20but%20doesn%E2%80%99t%20free%20the%20memory%20when%20it%E2%80%99s%20done%20with%20the%20data.%20Virtual%20memory%20that%20processes%20allocate%20to%20store%20their%20own%20data%20is%20called%20Private%20Bytes%2C%20so%20I%20opened%20Process%20Explorer%20and%20added%20the%20Private%20Bytes%20column%3A%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CIMG%20height%3D%22227%22%20mce_src%3D%22http%3A%2F%2Fblogs.technet.com%2Fphotos%2Fmarkrussinovich%2Fimages%2F2178605%2Foriginal.aspx%22%20original-url%3D%22http%3A%2F%2Fblogs.technet.com%2Fphotos%2Fmarkrussinovich%2Fimages%2F2178605%2Foriginal.aspx%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F120997iE1BCDDF4F76B4E1F%22%20style%3D%22WIDTH%3A%20550px%3B%20HEIGHT%3A%20227px%22%20width%3D%22550%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CSPAN%20style%3D%22mso-no-proof%3A%20yes%22%3E%20%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20On%20a%2032-bit%20Windows%20system%2C%20processes%20have%202%20GB%20of%20address%20space%20available%20to%20them%20by%20default%2C%20so%20the%20highest%20possible%20Private%20Bytes%20value%20is%20close%20to%202%20GB%2C%20which%20is%20exactly%20what%20the%20Sidebar%20process%20with%20process%20ID%204680%20had%20consumed.%20That%20confirmed%20it%3A%20a%20memory%20leak%20in%20Sidebar%20caused%20it%20to%20run%20out%20of%20address%20space%2C%20which%20in%20turned%20caused%20a%20memory%20allocation%20to%20fail%2C%20which%20finally%20caused%20a%20NULL-pointer%20reference%20and%20a%20crash.%20I%20suspect%20that%20the%20clock%20stopped%20when%20Sidebar%E2%80%99s%20address%20space%20was%20exhausted%20and%20the%20clock%20Gadget%20couldn%E2%80%99t%20allocate%20resources%20to%20update%20its%20graphic.%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20Next%20I%20had%20to%20determine%20which%20Gadget%20was%20causing%20the%20leak%2C%20which%20may%20or%20may%20not%20have%20been%20the%20frozen%20clock%20Gadget.%20The%20Sidebar%20consists%20of%20two%20processes%2C%20one%20Sidebar.exe%20process%20that%20hosts%20the%20Windows%20Gadgets%20and%20a%20child%20Sidebar.exe%20process%20for%20third-party%20Gadgets.%20At%20this%20point%20I%20knew%20that%20a%20third-party%20Gadget%20had%20leaked%20memory%20or%20caused%20the%20Sidebar%20to%20leak%2C%20but%20I%20had%20several%20third-party%20Gadgets%20running%20and%20I%20didn%E2%80%99t%20know%20which%20one%20to%20blame.%20Unfortunately%2C%20the%20Sidebar%20offers%20no%20way%20to%20track%20memory%20usage%20by%20Gadget%20(or%20any%20other%20resource%20usage%20for%20that%20matter)%2C%20so%20I%20had%20to%20apply%20manual%20steps%20to%20isolate%20the%20leak.%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20After%20restarting%20the%20Sidebar%2C%20I%20removed%20the%20third-party%20Gadgets%20and%20added%20them%20back%20one%20at%20a%20time%2C%20leaving%20each%20to%20run%20for%20a%20minute%20or%20two%20while%20I%20monitored%20Sidebar%E2%80%99s%20Private%20Bytes%20usage.%20I%20added%20the%20Private%20Bytes%20Delta%20column%20to%20Process%20Explorer%E2%80%99s%20display%20to%20make%20it%20easy%20to%20spot%20increases%2C%20and%20after%20adding%20one%20of%20the%20Gadgets%20I%20started%20to%20see%20periodic%20positive%20Private%20Bytes%20Delta%20values%2C%20implicating%20it%20as%20the%20leaker%3A%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CIMG%20height%3D%22207%22%20mce_src%3D%22http%3A%2F%2Fblogs.technet.com%2Fphotos%2Fmarkrussinovich%2Fimages%2F2178606%2Foriginal.aspx%22%20original-url%3D%22http%3A%2F%2Fblogs.technet.com%2Fphotos%2Fmarkrussinovich%2Fimages%2F2178606%2Foriginal.aspx%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F120998i583249DDA2F1A43C%22%20style%3D%22WIDTH%3A%20550px%3B%20HEIGHT%3A%20207px%22%20width%3D%22550%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CSPAN%20style%3D%22mso-no-proof%3A%20yes%22%3E%20%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20Now%20that%20I%20knew%20the%20guilty%20Gadget%2C%20I%20could%20have%20simply%20uninstalled%20it%20and%20considered%20the%20case%20closed.%20But%20I%20was%20curious%20to%20know%20how%20the%20Gadget%20had%20managed%20to%20cause%20a%20leak%20in%20the%20Sidebar%20%E2%80%93%20a%20leak%20that%20persisted%20even%20after%20I%20removed%20the%20Gadget.%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20I%20navigated%20to%20the%20Gadget%E2%80%99s%20install%20directory%20and%20opened%20its%20HTML%20file%20to%20see%20what%20it%20was%20doing.%20The%20Gadget%20consists%20of%20around%203-dozen%20lines%20of%20pretty%20simple%20Javascript%20and%20I%20didn%E2%80%99t%20spot%20anything%20amiss.%20To%20narrow%20in%20on%20the%20problematic%20code%2C%20I%20began%20commenting%20out%20pieces%20and%20re-adding%20the%20Gadget%20to%20the%20Sidebar%20until%20the%20leak%20disappeared.%20The%20code%20I%20was%20left%20with%20was%20a%20function%20the%20Gadget%20configured%20to%20execute%20every%2010%20seconds%20to%20update%20its%20graphics.%20It%20called%20the%20Sidebar%20background%20object%E2%80%99s%20%3CA%20class%3D%22%22%20href%3D%22http%3A%2F%2Fmsdn2.microsoft.com%2Fen-us%2Flibrary%2Faa359361.aspx%22%20mce_href%3D%22http%3A%2F%2Fmsdn2.microsoft.com%2Fen-us%2Flibrary%2Faa359361.aspx%20%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3ERemoveObjects%20%3C%2FA%3E%3C%2FFONT%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3Emethod%20and%20then%20added%20back%20graphics%20and%20text%20by%20calling%20the%20background%E2%80%99s%20%3CA%20class%3D%22%22%20href%3D%22http%3A%2F%2Fmsdn2.microsoft.com%2Fen-us%2Flibrary%2Faa359353.aspx%22%20mce_href%3D%22http%3A%2F%2Fmsdn2.microsoft.com%2Fen-us%2Flibrary%2Faa359353.aspx%20%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EAddImageObject%20%3C%2FA%3E%3C%2FFONT%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3Emethod.%20Here%E2%80%99s%20a%20simplified%20version%20of%20the%20relevant%20code%3A%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CSPAN%20style%3D%22mso-no-proof%3A%20yes%22%3E%20%3C%2FSPAN%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20%3CIMG%20height%3D%22128%22%20mce_src%3D%22http%3A%2F%2Fblogs.technet.com%2Fphotos%2Fmarkrussinovich%2Fimages%2F2178608%2Foriginal.aspx%22%20original-url%3D%22http%3A%2F%2Fblogs.technet.com%2Fphotos%2Fmarkrussinovich%2Fimages%2F2178608%2Foriginal.aspx%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F120999iF7A89781628F8193%22%20style%3D%22WIDTH%3A%20358px%3B%20HEIGHT%3A%20128px%22%20width%3D%22358%22%20%2F%3E%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20The%20fact%20that%20it%20was%20using%20these%20APIs%20correctly%20meant%20that%20the%20leak%20was%20in%20the%20Sidebar%E2%80%99s%20code%2C%20but%20a%20quick%20Internet%20search%20didn%E2%80%99t%20turn%20up%20any%20mentions%20of%20a%20leak%20in%20the%20background%20object.%20If%20Sidebar%20APIs%20had%20a%20memory%20leak%2C%20why%20wasn%E2%80%99t%20it%20well%20known%3F%20I%20scanned%20the%20source%20code%20to%20the%20other%20Gadget%E2%80%99s%20on%20my%20system%20and%20discovered%20that%20none%20of%20them%20used%20the%20APIs%2C%20which%20explained%20why%20the%20leak%20isn't%20commonly%20encountered.%20However%2C%20comments%20in%20the%20Windows%20Gadget%20Gallery%20for%20the%20Gadget%20that%20inadvertently%20caused%20the%20leak%20revealed%20that%20other%20users%20had%20noticed%20it.%20%3C%2FFONT%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%20class%3D%22MsoNormal%22%20style%3D%22MARGIN%3A%200in%200in%2010pt%22%3E%3CFONT%20face%3D%22Calibri%22%20size%3D%223%22%3E%20Having%20tracked%20the%20original%20unresponsive%20Gadget%20problem%20down%20to%20a%20leaky%20Sidebar%20API%2C%20I%20filed%20a%20bug%20in%20the%20Windows%20bug%20database%20and%20closed%20the%20case.%20%3C%2FFONT%3E%3C%2FP%3E%0A%20%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-723605%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20TechNet%20on%20Oct%2015%2C%202007%20Besides%20Aero%20Glass%2C%20one%20of%20the%20most%20visible%20features%20of%20Windows%20Vista%20is%20the%20Sidebar%20with%20its%20set%20of%20default%20Gadgets%2C%20like%20the%20clock%2C%20RSS%20feed%2C%20and%20photo%20viewer.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-723605%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMark%20Russinovich%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft
First published on TechNet on Oct 15, 2007

Besides Aero Glass, one of the most visible features of Windows Vista is the Sidebar with its set of default Gadgets, like the clock, RSS feed, and photo viewer. The convenience of having frequently-accessed information on the desktop and the ease of their development has led to the availability of literally thousands of third-party Gadgets through sites like the Windows Vista Gadget Gallery . I’ve downloaded and installed a few out of curiosity, and in some cases kept them in my Sidebar’s standard configuration, and never experienced a problem. A few days after installing a batch of new Gadgets, however, I noticed that a third-party clock Gadget had stopped updating, and so I set out to investigate.


My system was otherwise functioning normally, so my first step was to see if something was amiss with the Sidebar’s configuration. I right-clicked on the Sidebar screen area and selected the Properties menu item, but instead of displaying the Sidebar configuration dialog, the Sidebar crashed:



Gadgets run inside of shared Sidebar processes, so my first thought was that memory corruption in the Sidebar process had caused the clock to stop and subsequent crash, and verifying that theory required that I analyze the crash. The Windows Error Reporting (WER) service creates a crash-dump file, which is the saved state of a faulting process, in case you agree to send information to Microsoft about a problem. I clicked open the View Details area to see where Windows had saved the dump:



The last path displayed by the dialog, WERD8EE.tmp.mdmp, is a dump file, so I launched the Microsoft Debugging Tools for Windows Windbg utility and opened the file. When you open a dump file, Windbg automatically shows you the instruction that ultimately lead to the crash. In this case, it was a memory copy operation in Msvcrt, the Microsoft C Runtime:




The right side of the line showing the instruction indicates that the target address of the copy is 0. When a memory resource is exhausted, memory-allocation functions typically return address 0, also known as a NULL pointer, because that’s an illegal address by default for a Windows process (an application can manually create read/write memory at address zero, but in general it’s not done). The fact that Sidebar referenced address 0 didn’t conclusively mean the crash was due to low-memory instead of corruption, but it appeared likely.


I next looked at the code that led to the crash, which would tell me if it was a Gadget or the Sidebar itself that had passed a NULL pointer to the C Runtime. To do so, I opened Windbg’s stack dialog:




I had previously configured Windbg’s symbol path to point at the Microsoft symbol server so that Windbg reports names of internal functions in Windows images, because knowing function names can often make understanding a dump file easier. The functions listed in the stack trace implied that Sidebar was querying the version of a “package” when it crashed. I’m not sure what the Sidebar calls a package, but the trace did seem to show that Sidebar was the culprit, not a Gadget.


So had Sidebar run out of memory? There are several types of resource exhaustion that can cause a memory allocation to fail. For example, the system could have run out of committable memory, the process could have consumed all the memory in its own address space, or an internal heap could have reached its maximum size.


I started by checking the committed memory, since that was quick. Total commitable memory, also known as the commit limit, is the sum of the paging file(s) and most of physical memory. When commitable memory runs low, Windows Vista’s low-resource watchdog warns you by presenting a list of processes consuming the most memory and gives you the option of terminating them to relieve the memory pressure. I hadn’t seen a warning, so I doubted that this was the cause, but opened Process Explorer’s System Information dialog to check anyway:




As I suspected, there was plenty of available Committable memory. I next looked at Sidebar’s virtual memory usage. Memory leaks are caused when a process allocates virtual memory, stores some data in it, uses the data, but doesn’t free the memory when it’s done with the data. Virtual memory that processes allocate to store their own data is called Private Bytes, so I opened Process Explorer and added the Private Bytes column:




On a 32-bit Windows system, processes have 2 GB of address space available to them by default, so the highest possible Private Bytes value is close to 2 GB, which is exactly what the Sidebar process with process ID 4680 had consumed. That confirmed it: a memory leak in Sidebar caused it to run out of address space, which in turned caused a memory allocation to fail, which finally caused a NULL-pointer reference and a crash. I suspect that the clock stopped when Sidebar’s address space was exhausted and the clock Gadget couldn’t allocate resources to update its graphic.


Next I had to determine which Gadget was causing the leak, which may or may not have been the frozen clock Gadget. The Sidebar consists of two processes, one Sidebar.exe process that hosts the Windows Gadgets and a child Sidebar.exe process for third-party Gadgets. At this point I knew that a third-party Gadget had leaked memory or caused the Sidebar to leak, but I had several third-party Gadgets running and I didn’t know which one to blame. Unfortunately, the Sidebar offers no way to track memory usage by Gadget (or any other resource usage for that matter), so I had to apply manual steps to isolate the leak.


After restarting the Sidebar, I removed the third-party Gadgets and added them back one at a time, leaving each to run for a minute or two while I monitored Sidebar’s Private Bytes usage. I added the Private Bytes Delta column to Process Explorer’s display to make it easy to spot increases, and after adding one of the Gadgets I started to see periodic positive Private Bytes Delta values, implicating it as the leaker:




Now that I knew the guilty Gadget, I could have simply uninstalled it and considered the case closed. But I was curious to know how the Gadget had managed to cause a leak in the Sidebar – a leak that persisted even after I removed the Gadget.


I navigated to the Gadget’s install directory and opened its HTML file to see what it was doing. The Gadget consists of around 3-dozen lines of pretty simple Javascript and I didn’t spot anything amiss. To narrow in on the problematic code, I began commenting out pieces and re-adding the Gadget to the Sidebar until the leak disappeared. The code I was left with was a function the Gadget configured to execute every 10 seconds to update its graphics. It called the Sidebar background object’s RemoveObjects method and then added back graphics and text by calling the background’s AddImageObject method. Here’s a simplified version of the relevant code:




The fact that it was using these APIs correctly meant that the leak was in the Sidebar’s code, but a quick Internet search didn’t turn up any mentions of a leak in the background object. If Sidebar APIs had a memory leak, why wasn’t it well known? I scanned the source code to the other Gadget’s on my system and discovered that none of them used the APIs, which explained why the leak isn't commonly encountered. However, comments in the Windows Gadget Gallery for the Gadget that inadvertently caused the leak revealed that other users had noticed it.


Having tracked the original unresponsive Gadget problem down to a leaky Sidebar API, I filed a bug in the Windows bug database and closed the case.