locked
LoadLibrary / FreeLibrary mismatch error RRS feed

  • Question

  • I got app verifier logs from customer for the application I released to them. The logs shows "The application did not call FreeLibrary for each LoadLibrary call". But the call stack in the logs map to the code which does not call LoadLibrary. Then what does this error mean? What could be the possible problem in the code which the app verifier logs are showing?

    Regards,
    Asif.

    Thursday, June 4, 2009 1:54 PM

Answers

  • In a process, a reference count is incremented each time LoadLibrary is called within the process and decremented each time FreeLibrary is called.  The error message occurs when this number is non-zero hence the error, "Mismatched Load/FreeLibrary."  This is a process level error so it doesn't necessarily have to occur in the same code that is displayed in the callstack.  So a LoadLibrary from ANY DLL could cause this error, not just the code identified.  This error should be occurring when the process is exiting and shows that something didn't get cleaned up.

    You will need to look at all your code including any third party DLLs you may be using to determine which one is not playing nicely.


    why do you robot?
    • Proposed as answer by therobotgeek Thursday, June 4, 2009 7:19 PM
    • Marked as answer by Am_ac1 Friday, June 5, 2009 4:05 PM
    Thursday, June 4, 2009 7:18 PM
  • No, it should not generate the error because the reference count is per process. 
    why do you robot?
    • Marked as answer by Am_ac1 Friday, June 5, 2009 4:05 PM
    Friday, June 5, 2009 2:39 PM

All replies

  • Hi Asif,


    "The application did not call FreeLibrary for each LoadLibrary call"

    This message looks like developer thrown message. If yes, you need to check when you are throwing this message to log file in your application. I mean in which part of your code you are throwing this message to log file. So that it will be easy to anaylize.


    Please let me know if my understanding is wrong.

    Regards,
    Malleswar
    Thursday, June 4, 2009 2:00 PM
  • Sometimes this is even shown even if you do not call LoadLibrary from your source code. I have seen it while working with App Verifier. If you are checking for memory leak, go for 3rd party tool or use Remote Performance Monitor from Windows Platform Builder 5.0. You can look at various parameters to monitor, right from cpu usage to global memory usage.

    Thank you,
    C.E.D
    Thursday, June 4, 2009 2:06 PM
  • No. This is not a developer thrown message. Following is the extract of the logs that app verifier have generated,

    # DESCRIPTION BEGIN
    The application did not call FreeLibrary for each LoadLibrary call
    # DESCRIPTION END
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x36da406c: shim_verifier.dll!(null) + 406ch
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x7b9213a4: tpcutil.dll!(null) + 913a4h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x7b9217d4: tpcutil.dll!(null) + 917d4h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x7b89e6cc: tpcutil.dll!(null) + e6cch
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x7b89e88c: tpcutil.dll!(null) + e88ch
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x7b927878: tpcutil.dll!(null) + 97878h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x03f66d30: coredll.dll!(null) + 1cd30h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x03f66da4: coredll.dll!(null) + 1cda4h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x03f66ea8: coredll.dll!(null) + 1cea8h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x03f625a4: coredll.dll!(null) + 185a4h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x03fa9f90: coredll.dll!(null) + 5ff90h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x03f62738: coredll.dll!(null) + 18738h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x36da4030: shim_verifier.dll!(null) + 4030h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x02376f8c: ole32.dll!(null) + 5f8ch
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x0237871c: ole32.dll!(null) + 771ch
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x02378a64: ole32.dll!(null) + 7a64h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x023744a4: ole32.dll!(null) + 34a4h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x02379338: ole32.dll!(null) + 8338h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x02374248: ole32.dll!(null) + 3248h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x023742f4: ole32.dll!(null) + 32f4h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x36016038: MyApplication.exe!(null) + 16038h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x36049570: MyApplication.exe!(null) + 49570h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x36049810: MyApplication.exe!(null) + 49810h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x360a6358: MyApplication.exe!(null) + a6358h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x03f67760: coredll.dll!(null) + 1d760h
    | shim_verifier.dll 5 | 2 nk.exe 80016ea0'   0x8d715688   (custsat.dll)
    # LOGENTRY shim_verifier.dll 6 'Mismatched Load/FreeLibrary.     1 items at 0x36da406c


    Regards,
    Asif.
    Thursday, June 4, 2009 2:32 PM
  • Hi C.E.D,

    This log is sent from customer and they use app verifier.
    Thursday, June 4, 2009 4:14 PM
  • In a process, a reference count is incremented each time LoadLibrary is called within the process and decremented each time FreeLibrary is called.  The error message occurs when this number is non-zero hence the error, "Mismatched Load/FreeLibrary."  This is a process level error so it doesn't necessarily have to occur in the same code that is displayed in the callstack.  So a LoadLibrary from ANY DLL could cause this error, not just the code identified.  This error should be occurring when the process is exiting and shows that something didn't get cleaned up.

    You will need to look at all your code including any third party DLLs you may be using to determine which one is not playing nicely.


    why do you robot?
    • Proposed as answer by therobotgeek Thursday, June 4, 2009 7:19 PM
    • Marked as answer by Am_ac1 Friday, June 5, 2009 4:05 PM
    Thursday, June 4, 2009 7:18 PM
  • So, for ex, say, when a process "PA" is exiting, it may be possible that some other process "PB" is still using this library. Hence the reference count will not be zero when "PA" is exiting as process "PB" is still holding it. So in that case will appverifier generate the "LoadLibrary / FreeLibrary" mismatch error?

    Regards.
    Friday, June 5, 2009 2:21 PM
  • No, it should not generate the error because the reference count is per process. 
    why do you robot?
    • Marked as answer by Am_ac1 Friday, June 5, 2009 4:05 PM
    Friday, June 5, 2009 2:39 PM