win-pvdrivers

diff shutdownmon/shutdownmon.c @ 979:8f483a2b2991

Fix up PREfast warnings
author James Harper <james.harper@bendigoit.com.au>
date Sun Apr 15 19:47:10 2012 +1000 (2012-04-15)
parents 5bdb7251370c
children
line diff
     1.1 --- a/shutdownmon/shutdownmon.c	Sun Apr 15 18:57:34 2012 +1000
     1.2 +++ b/shutdownmon/shutdownmon.c	Sun Apr 15 19:47:10 2012 +1000
     1.3 @@ -187,10 +187,15 @@ do_hibernate()
     1.4    printf("token_handle = %p\n", token_handle);
     1.5  
     1.6    tp = malloc(sizeof(TOKEN_PRIVILEGES) + sizeof(LUID_AND_ATTRIBUTES));
     1.7 +  if (!tp) {
     1.8 +    printf("malloc failed\n");
     1.9 +    CloseHandle(token_handle);
    1.10 +    return;
    1.11 +  }
    1.12    tp->PrivilegeCount = 1;
    1.13 -  if (!LookupPrivilegeValueA(NULL, SE_SHUTDOWN_NAME, &tp->Privileges[0].Luid))
    1.14 -  {
    1.15 +  if (!LookupPrivilegeValueA(NULL, SE_SHUTDOWN_NAME, &tp->Privileges[0].Luid)) {
    1.16      printf("LookupPrivilegeValue failed\n");
    1.17 +    free(tp);
    1.18      CloseHandle(token_handle);
    1.19      return;
    1.20    }
    1.21 @@ -198,15 +203,16 @@ do_hibernate()
    1.22    tp->Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    1.23    if (!AdjustTokenPrivileges(token_handle, FALSE, tp, 0, NULL, NULL))
    1.24    {
    1.25 +    printf("AdjustTokenPrivileges failed\n");
    1.26 +    free(tp);
    1.27      CloseHandle(token_handle);
    1.28      return;
    1.29    }
    1.30  
    1.31 -  if (!SetSuspendState(TRUE, FALSE, FALSE))
    1.32 -  {
    1.33 +  if (!SetSuspendState(TRUE, FALSE, FALSE)) {
    1.34      printf("hibernate failed\n");
    1.35    }
    1.36 -
    1.37 +  free(tp);
    1.38    CloseHandle(token_handle);
    1.39  }
    1.40  
    1.41 @@ -227,10 +233,16 @@ do_shutdown(BOOL bRebootAfterShutdown)
    1.42    printf("token_handle = %p\n", token_handle);
    1.43  
    1.44    tp = malloc(sizeof(TOKEN_PRIVILEGES) + sizeof(LUID_AND_ATTRIBUTES));
    1.45 +  if (!tp) {
    1.46 +    printf("malloc failed\n");
    1.47 +    CloseHandle(token_handle);
    1.48 +    return;
    1.49 +  }
    1.50    tp->PrivilegeCount = 1;
    1.51    if (!LookupPrivilegeValueA(NULL, SE_SHUTDOWN_NAME, &tp->Privileges[0].Luid))
    1.52    {
    1.53      printf("LookupPrivilegeValue failed\n");
    1.54 +    free(tp);
    1.55      CloseHandle(token_handle);
    1.56      return;
    1.57    }
    1.58 @@ -238,10 +250,11 @@ do_shutdown(BOOL bRebootAfterShutdown)
    1.59    tp->Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    1.60    if (!AdjustTokenPrivileges(token_handle, FALSE, tp, 0, NULL, NULL))
    1.61    {
    1.62 +    free(tp);
    1.63      CloseHandle(token_handle);
    1.64      return;
    1.65    }
    1.66 -
    1.67 +  #pragma warning(suppress:28159)
    1.68    if (!InitiateSystemShutdownEx(NULL, NULL, 0, TRUE, bRebootAfterShutdown, SHTDN_REASON_FLAG_PLANNED | SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER))
    1.69    {
    1.70      printf("InitiateSystemShutdownEx failed\n");
    1.71 @@ -249,6 +262,7 @@ do_shutdown(BOOL bRebootAfterShutdown)
    1.72    }
    1.73    printf("InitiateSystemShutdownEx succeeded\n");
    1.74  
    1.75 +  free(tp);
    1.76    CloseHandle(token_handle);
    1.77  }
    1.78