Skip to content

Commit

Permalink
Code review: visibility, resources on exception
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwiddis committed Aug 26, 2018
1 parent 3fe60dc commit f34e7a4
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public int getResultCount() {
/**
* Increment the result count by one.
*/
public void incrementResultCount() {
private void incrementResultCount() {
this.resultCount++;
}
}
Expand Down Expand Up @@ -460,17 +460,20 @@ public static <T extends Enum<T>> WmiResult<T> queryWMI(WmiQuery<T> query, int t
IWbemServices svc = connectServer(query.getNameSpace());

// Send query
IEnumWbemClassObject enumerator = selectProperties(svc, query);

try {
return enumerateProperties(enumerator, query.getPropertyEnum(), timeout);
} catch (TimeoutException e) {
throw new TimeoutException(e.getMessage());
IEnumWbemClassObject enumerator = selectProperties(svc, query);

try {
return enumerateProperties(enumerator, query.getPropertyEnum(), timeout);
} finally {
// Cleanup
enumerator.Release();
}
} finally {
// Cleanup
enumerator.Release();
svc.Release();
}

}

/*
Expand Down Expand Up @@ -560,7 +563,6 @@ public static <T extends Enum<T>> IEnumWbemClassObject selectProperties(IWbemSer
OleAuto.INSTANCE.SysFreeString(queryStr);
OleAuto.INSTANCE.SysFreeString(wql);
if (COMUtils.FAILED(hres)) {
svc.Release();
throw new COMException(String.format("Query '%s' failed.", sb.toString()), hres);
}
return new IEnumWbemClassObject(pEnumerator.getValue());
Expand Down

0 comments on commit f34e7a4

Please sign in to comment.