From 68a16c2c4095443f23b8bf9da619128d6fa6b566 Mon Sep 17 00:00:00 2001 From: snoop Date: Wed, 12 Apr 2017 15:45:56 +0900 Subject: [PATCH] added wmi crawler release --- .../crawler/wmi/WMICrawlerWindows.java | 68 ++++++++++++++++--- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerWindows.java b/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerWindows.java index 958cc07..4ee0d82 100644 --- a/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerWindows.java +++ b/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerWindows.java @@ -32,15 +32,38 @@ public class WMICrawlerWindows extends WMICrawlerOS { ActiveXComponent wmi = null; wmi = new ActiveXComponent("WbemScripting.SWbemLocator"); - Variant conRet = wmi.invoke("ConnectServer", new Variant(ip), new Variant(nameSpace), new Variant(id), new Variant(pw)); + Variant vIp = new Variant(ip); + Variant vNs = new Variant(nameSpace); + Variant vId = new Variant(id); + Variant vPw = new Variant(pw); - ActiveXComponent wmiconnect = new ActiveXComponent(conRet.toDispatch()); + Variant conRet = wmi.invoke("ConnectServer", vIp, vNs, vId, vPw); - Variant vCollection = wmiconnect.invoke("ExecQuery", new Variant(query)); + vIp.safeRelease(); + vNs.safeRelease(); + vId.safeRelease(); + vPw.safeRelease(); + + Dispatch disConret = conRet.toDispatch(); + + ActiveXComponent wmiconnect = new ActiveXComponent(disConret); + disConret.safeRelease(); + + Variant vQuery = new Variant(query); + + Variant vCollection = wmiconnect.invoke("ExecQuery", vQuery); + + wmiconnect.safeRelease(); + vQuery.safeRelease(); EnumVariant enumVariant = new EnumVariant(vCollection.toDispatch()); + wmi.safeRelease(); + conRet.safeRelease(); + vCollection.safeRelease(); + + Variant vItem = null; Dispatch item = null; List columns = null; @@ -48,7 +71,8 @@ public class WMICrawlerWindows extends WMICrawlerOS { List> resultMapList = new ArrayList>(); while (enumVariant.hasMoreElements()) { - item = enumVariant.nextElement().toDispatch(); + vItem = enumVariant.nextElement(); + item = vItem.toDispatch(); if (columns == null) { columns = getColumns(item); @@ -57,14 +81,20 @@ public class WMICrawlerWindows extends WMICrawlerOS { resultMap = new HashMap(); String name = null; String value = null; + Variant vValue = null; for(int indexI = 0 ; indexI < columns.size(); ++indexI) { name = columns.get(indexI); - value = Dispatch.call(item, name).toString(); + vValue = Dispatch.call(item, name); + value = vValue.toString(); resultMap.put(name, value); + vValue.safeRelease(); } resultMapList.add(resultMap); + + vItem.safeRelease(); + item.safeRelease(); } return resultMapList; } @@ -75,17 +105,37 @@ public class WMICrawlerWindows extends WMICrawlerOS { Variant propertyesa = Dispatch.call(item, "Properties_"); - Variant newEnum = Dispatch.call(propertyesa.toDispatch(), "_NewEnum"); + Dispatch disProperty = propertyesa.toDispatch(); + + + Variant newEnum = Dispatch.call(disProperty, "_NewEnum"); + + propertyesa.safeRelease(); + disProperty.safeRelease(); EnumVariant enumv = newEnum.toEnumVariant(); - while (enumv.hasMoreElements()) { - Dispatch vv = enumv.nextElement().toDispatch(); + newEnum.safeRelease(); - String vs = Dispatch.call(vv, "Name").toString(); + Variant vElem = null; + Dispatch disElem = null; + Variant vName = null; + + while (enumv.hasMoreElements()) { + vElem = enumv.nextElement(); + disElem = vElem.toDispatch(); + + vName = Dispatch.call(disElem, "Name"); + String vs = vName.toString(); columns.add(vs); + + disElem.safeRelease(); + vElem.safeRelease(); + vName.safeRelease(); } + + enumv.safeRelease(); return columns; }