Thread: leaking mutexes, with no mutex in code

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    188

    leaking mutexes, with no mutex in code

    hello, i'm running into a very weird problem and maybe someone with a lot of windows experience can chime in.

    an application i'm testing with shows it's leaking handles (according to performance monitor). i ran sysinternals handle on the service, and mutants are consistently going up at a rate of 1 every 5 or 6 seconds.

    the weird part is, there is not a single reference to a mutex in the code.

    the machine is running windows 2000, and the handle leak doesn't appear on another test box running XP...

    any ideas? thanks.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> there is not a single reference to a mutex in the code
    It's not just your code running within your process. Use process explorer to see what DLL's are loaded. You may be able to see which module is leaking as well.

    gg

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    188
    thanks for the quick reply!

    i opened up process explorer, and indeed there are many DLLs loaded. my application is statically compiled, and the only DLLs loaded are all from microsoft.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    You could use the debugger to narrow down in what part of the code the handle count increases.

    gg

  5. #5
    Registered User
    Join Date
    Aug 2008
    Posts
    188
    thanks again!

    i'm new to all of these "low-level" debugging...and only recently discovered the sysinternals suite. do you have any links/articles that i could read? i'm guessing you're referring to cdb.exe?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What debugger you should/could use depends on what compiler you use. Visual Studio has a built-in debugger that is pretty useful.

    However, trying do debug code that isn't yours (e.g. MS code) can be very hard - the best effort is probably a "divide and conquer" - find a few likely candidates of functions outside of your application that could possibly cause this problem, and try to exercise those in a smaller test-app. Then strip down your code to a bare minimum.

    Once you know that, you may of course not be able to do anything about it, as you don't have the source-code for the DLL anyways...

    Another option is to start your applicatin as usual, then start WinDBG (Freely available as download from MS), and set a breakpoint in the suitable "create mutex" or such function, and look at the call-stack.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mutex across multiple source files
    By Quasar in forum Linux Programming
    Replies: 7
    Last Post: 12-04-2007, 08:25 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  4. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM