Jump to content
Sign in to follow this  
blademonkey

Need Help Finding Memory leak

Recommended Posts

blademonkey

Hey Guys,

I seem to be getting a memory leak on the following project. it's pretty bad, about 30 Bytes/second.I was hoping someone can point me in the right direction. thanks, here are the details.

This is an odd project I'm working on. We have this process called an RVI (Remote Verification Install), which is where we send a CD with XP patches and updates to in-house software to our remote users that don't have broadband (about 400).While they run the update procedure we disable their homedir priviledges so that they can't run the inhouse software until after the update. After this RVI CD is run, a log file is produced and is uploaded to a share on our servers.

My script/app will parse through the logs and look for a certain value (status=Success) to find which folders to enable disable.

The $Source Var assigns the location of the folders where the log file is being uploaded.

The $Target Var assigns the location of the folders that need to have permissions changed.

The $BinPath Var is the location of the app i will use to set permissions (SuperCACLS).

The $sIndexDir is where the log file and permission sets are going to be saved.

The $sNameConvFile is the filename that will cross reference the source folder names with their appropriate target folders.

Here's the code. I will upload a zip file with the structure of the folder so you can all run it and see the leak.

#include<guiconstants.au3>
#include <File.au3>
#include <Array.au3>
opt("GUIOnEventMode",1)
;~ If ProcessExists(@ScriptName) then processclose(@ScriptName)

$sBinPath       =   iniread(StringTrimRight(@ScriptName,3)&"ini","PATH","BIN","")   ;Path to the Modacl, Reacl and Pracl executables.
$sSourceDir     =   iniread(StringTrimRight(@ScriptName,3)&"ini","PATH","SOURCE","");Path to the RVI Logs to be Parsed
$sTargetDir     =   iniread(StringTrimRight(@ScriptName,3)&"ini","PATH","TARGET","");Path to the folders to be modded
$sIndexDir    = iniread(StringTrimRight(@ScriptName,3)&"ini","PATH","INDEX","");Path to the index folder (for use of this script only).
$sNameConvFile  =   iniread(StringTrimRight(@ScriptName,3)&"ini","PATH","NAMES","");Path to the ID2Name convertion file.


$sBinPath       =   _checkpath($sSourceDir)
$sSourceDir     =   _checkpath($sSourceDir)
$sTargetDir     =   _checkpath($sTargetDir)
$sIndexDir    = _checkpath($sIndexDir)
$sNameConvFile  =   _checkpath($sIndexDir)

$iGUISizeX = 550
$iGUISizeY = 400

;~ If FileExists($sIndexDir&'\_Index.txt') =0 then IndexPath()
Dim $aDirlistTBP[1], $aRVIFlagNoFlag[1], $aRVIFlagFailed[1], $aRVIFlagSuccess[1]
$iHour              = @HOUR
$iMin               = @MIN
$iSec               = @SEC
$Starttime          = @HOUR &":"&@MIN&":"&@SEC
$timer              = TimerInit()
$elapsedtime        =  TimerDiff($timer)
$Title              = "RVI Log Parser " & "  -  Start: "& $Starttime & "      Elapsed: "
$sRVIFile           = "Security07_09-SMS.mkr"
$aCurDirList        = ScanDir($sSourceDir)
$sList              = _ArrayToString($aCurDirList,"|",1)
$sNewProcessList    = ""
$sProcessList       = _ArrayToString($aDirlistTBP,"|",1)
$sRVIFlagNoFlag     = ''
$sNewRVIFlagNoFlag  = '' 
$sRVIFlagSuccess    = ''
$sNewRVIFlagSuccess = ''
$sRVIFlagFailed     = ''
$sNewRVIFlagFailed  = ''

    $gMain = GUICreate($Title& $elapsedtime,550, 400)       ;  GUI element: Main Window
    GUISetState(@SW_SHOW)
    WinSetOnTop($Title& $elapsedtime,"",1)
    GUICtrlCreateLabel("Home Folders", 20, 15)              ;  GUI element:     Label for First List Box
    $gBackupBTN = GUICtrlCreateButton("Backup",10,$iGUISizeY-30);  GUI element      Backup Button
    $gList = GUICtrlCreateList("", 10, 30, 100,150)         ;  GUI element:     list of Current folders
    GUICtrlCreateLabel("RVILOG", 130, 15)                   ;  GUI element      RVILOG
    $gRVIlogList = GUICtrlCreateList("",110,30,100,150)     ;  GUI element      Label
    GUICtrlCreateLabel("Flag=Success", 230, 15)             ;  GUI element      Flag=Success
    $gRVIFlagSuccess = GUICtrlCreateList("",220,30,100,150) ;  GUI element
    GUICtrlCreateLabel("Flag=Failed", 330, 15)              ;  GUI element      
    $gRVIFlagFailed = GUICtrlCreateList("",320,30,100,150)  ;  GUI element
    GUICtrlCreateLabel("No Flag", 430, 15)                  ;  GUI element      
    $gRVIFlagNoFlag = GUICtrlCreateList("",420,30,100,150)  ;  GUI element
    GUICtrlCreateLabel("Status:", 20, 185)                  ;  GUI element
    $gStatus = GUICtrlCreateList("",10,200,300,150,$WS_DISABLED);  GUI element
    GUICtrlCreateLabel("Enabled", 325, 185)                 ;  GUI element      
    $gEnabledFolders = GUICtrlCreateList("",320,200,100,150);  GUI element
    GUICtrlCreateLabel("Enabled", 325, 185)                 ;  GUI element      
    $gDisabledFolders = GUICtrlCreateList("",320,200,100,150);  GUI element

    GUICtrlSetData($gList,$sList)
    GUICtrlSetData($gRVIlogList,'')
    GUICtrlSetData($gRVIlogList,$sProcessList)
    GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
    GUICtrlSetData($gStatus,''  )
    GUICtrlSetData($gRVIFlagSuccess,'')
    GUICtrlSetData($gRVIFlagFailed,'')
    GUICtrlSetData($gRVIFlagNoFlag,'')
while 1
;~  ConsoleWrite(   @lf  & "$aDirlistTBP: " &  ubound($aDirlistTBP) &@lf & _
;~                   "$aCurDirList:  " &  ubound($aCurDirList) &@lf & _
;~                  "$aRVIFlagNoFlag: " &  ubound($aRVIFlagNoFlag) &@lf & _
;~                  "$aRVIFlagFailed: " &  ubound($aRVIFlagFailed) &@lf & _
;~                  "$aRVIFlagSuccess: " &  ubound($aRVIFlagFailed)&@lf )
                    
    
    $aNewDirList = ScanDir($sSourceDir)                                 ;  List folders into the Array New Dir LIst
    if _arrayCompare($aNewDirList,$aCurDirList)=0 Then 
        $aCurDirList = $aNewDirList
        $sList = _ArrayToString($aCurDirList,"|",1)
        GUICtrlSetData($gList,'')
        GUICtrlSetData($gList,$sList)
    EndIf
    for $x = 1 to UBound($aCurDirList)-1                                ;   For Loop
        if fileexists($sSourceDir&'\'&$aCurDirList[$x]&'\'&$sRVIFile) Then ;    If RVILog.txt exists in current folder in Array
            if _ArraySearch($aDirlistTBP,$aCurDirList[$x])=-1 Then      ;   If Current Folder is not in Dirlist Array   
                _ArrayAdd($aDirlistTBP,$aCurDirList[$x])                ;       Add to Processing Array
                $sNewProcessList = _ArrayToString($aDirlistTBP,"|",1)   ;       Convert DirList Array to String
            EndIf
        Elseif fileexists($sSourceDir&'\'&$aCurDirList[$x]&'\'&$sRVIFile)=0 Then
            _Arraycleanup($aDirlistTBP,$aCurDirList[$x],$sNewProcessList)
            _Arraycleanup($aRVIFlagSuccess,$aCurDirList[$x],$sNewRVIFlagSuccess)
            _Arraycleanup($aRVIFlagFailed,$aCurDirList[$x],$sNewRVIFlagFailed)
            _Arraycleanup($aRVIFlagNoFlag,$aCurDirList[$x],$sNewRVIFlagNoFlag)
        EndIf
    Next
    
    For $x = 1 to UBound($aDirlistTBP)-1
        $sScanResults = _ScanFileline($sSourceDir&'\'&$aDirlistTBP[$x]&'\'&$sRVIFile)
        Switch $sScanResults
            Case "Success"
                if _ArraySearch($aRVIFlagSuccess,$aDirlistTBP[$x])=-1 Then
                   _ArrayAdd($aRVIFlagSuccess,$aDirlistTBP[$x])
                   $sNewRVIFlagSuccess = _ArrayToString($aRVIFlagSuccess,"|",1)
                   _Arraycleanup($aRVIFlagFailed,$aDirlistTBP[$x],$sNewRVIFlagFailed)
                   _Arraycleanup($aRVIFlagNoFlag,$aDirlistTBP[$x],$sNewRVIFlagNoFlag)
                EndIf
            Case "failed"
                if _ArraySearch($aRVIFlagFailed,$aDirlistTBP[$x])=-1 Then
                    _ArrayAdd($aRVIFlagFailed,$aDirlistTBP[$x])
                    $sNewRVIFlagFailed = _ArrayToString($aRVIFlagFailed,"|",1)
                    _Arraycleanup($aRVIFlagSuccess,$aDirlistTBP[$x],$sNewRVIFlagSuccess)
                    _Arraycleanup($aRVIFlagNoFlag,$aDirlistTBP[$x],$sNewRVIFlagNoFlag)
                EndIf
            Case "NoFlag" or ""
                if _ArraySearch($aRVIFlagNoFlag,$aDirlistTBP[$x])=-1 Then
                   _ArrayAdd($aRVIFlagNoFlag,$aDirlistTBP[$x])
                   $sNewRVIFlagNoFlag = _ArrayToString($aRVIFlagNoFlag,"|",1)
                   _Arraycleanup($aRVIFlagSuccess,$aDirlistTBP[$x],$sNewRVIFlagSuccess)
                   _Arraycleanup($aRVIFlagFailed,$aDirlistTBP[$x],$sNewRVIFlagFailed)
               EndIf
           case Else
                if _ArraySearch($aRVIFlagNoFlag,$aDirlistTBP[$x])=-1 Then
                   _ArrayAdd($aRVIFlagNoFlag,$aDirlistTBP[$x])
                   $sNewRVIFlagNoFlag = _ArrayToString($aRVIFlagNoFlag,"|",1)
                   _Arraycleanup($aRVIFlagSuccess,$aDirlistTBP[$x],$sNewRVIFlagSuccess)
                   _Arraycleanup($aRVIFlagFailed,$aDirlistTBP[$x],$sNewRVIFlagFailed)
               EndIf               
        EndSwitch
    Next

    Setctrldata($sNewProcessList,       $sProcessList,      $gRVIlogList)   
    Setctrldata($sNewRVIFlagSuccess,    $sRVIFlagSuccess,   $gRVIFlagSuccess)   
    Setctrldata($sNewRVIFlagFailed,     $sRVIFlagFailed,    $gRVIFlagFailed)
    Setctrldata($sNewRVIFlagNoFlag,     $sRVIFlagNoFlag,    $gRVIFlagNoFlag)


;~  if $elapsedtime <> TimerDiff($timer) Then
;~      $elapsedtime = round(TimerDiff($timer)/1000,0)
;~      WinSetTitle($Title,"",$Title & $elapsedtime)
;~  EndIf
    For $x = 1 to ubound($aRVIFlagSuccess)-1 
;~      $sPermResults = EnablePerm($aRVIFlagSuccess[$x])
;~      $Guiread = GUICtrlRead($gStatus)
;~      
;~      if $Guiread <> "test1" then GUICtrlSetData($gStatus,"Test1")
;~      if $Guiread <> $aRVIFlagSuccess[$x] then    GUICtrlSetData($gStatus,$aRVIFlagSuccess[$x])
;~      ConsoleWrite($sPermResults&@lf)
;~              
    Next
    sleep(200)
WEnd

;~ Title:           ScanDir
;~ Description:     Look for new Log files
Func ScanDir($sX)
    $aX = _FileListToArray($sX,"*",2)
    _ArraySort($aX,0,1)
    return $aX
EndFunc

;~ Title:           IndexPath
;~ Description:     Creates an Index file of the permission of the Target Folders.
;~                  Creates Restore files for the permissions of the Target folders.
Func IndexPath()    
    runwait(@comspec & ' /c ' & 'pracl.exe /xs /b '&$sTargetDir&'> ' & $sIndexDir&'\_Index.txt',@ScriptDir,@sw_hide)
    runwait(@ComSpec & ' /c ' & 'for /f "tokens=* " %A in (''dir /ad /b '&$sTargetDir &''') do pracl.exe '&$sTargetDir&'\%A /s /b /d /bat '&$sIndexDir&'\%A.bat',@ScriptDir,@sw_hide)
EndFunc

;~ Title:           _Checkpath
;~ Description:     Checks the path string specified in the INI file.  
;~                  If the string does not contain a \\ or *:\ then it assumes that the folder is the current folder.
Func _checkpath($sX)
    If $sX <> "" then 
        Select 
            Case stringleft($sX,2) = "\\" 
                Return $sX
            Case StringMid($sX, 2, 2)= ":\"             
                Return $sX
            Case Else
                Return FileGetLongName(@scriptdir & "\" & $sX)
        EndSelect
    Else
        MsgBox(0,"Error","String is Empty")
    EndIf
EndFunc

;~ Title:           _arrayCompare
;~ Description:     Compare two 1D array.
Func _arrayCompare($a1,$a2)
    $y = 0
    if IsArray($a1) and IsArray($a2) Then
        if UBound($a1) = Ubound($a2) Then
            for $x = 1 to ubound($a1)-1 
                if $a1[$x] = $a2[$x] then $y += 1
            Next
            if $y = ubound($a1)-1 then 
                Return 1
            else 
                Return 0
            Endif
        Else
            Return 0
        EndIf
    Else
        Return ""
    EndIf
EndFunc

;~ Title:           SpecialEvents
;~ Description:     System Controls.
Func SpecialEvents()
    Select
        Case @GUI_CTRLID = $GUI_EVENT_CLOSE
            Exit
        Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE
            WinSetState(@GUI_CTRLID,'',@SW_MINIMIZE) 
    EndSelect
    
EndFunc

Func _ScanFileline($file)
    $iLineCount = _FileCountLines($file)
    $iSearchVal=0
    for $y = 1 to $iLineCount 
        $sLineRead = FileReadLine($file,$y)
        $iSearchVal = StringInStr($sLineRead,"Status")
        If $iSearchVal<>0 Then  
            $aSplit = StringSplit($sLineRead,"=")
            if ubound($aSplit) >= 3 then 
                Return $aSplit[2]
            else 
                Return "noflag"
            endif
        Endif
    Next
    if $iSearchVal=0 then Return "Noflag"
EndFunc

Func Setctrldata(byref $txt1,ByRef $txt2,$gCtrl)
    if $txt1<>$txt2 Then
        $txt2 = $txt1
        GUICtrlSetData($gCtrl,"")
        GUICtrlSetData($gCtrl,$txt1)
    EndIf
EndFunc

Func _ArrayCleanup(byref $Array,Byref $item, byref $newstring)
    if _ArraySearch($Array,$item,1) <> -1 Then
        _ArrayDelete($Array,$Array)
        $newstring = _ArrayToString($Array,"|",1)
    EndIf
    $array[0] = UBound($Array)
    if _ArraySearch($array,"",1)<>-1 Then
        _ArrayDelete($array,_ArraySearch($array,"",1))
        EndIf
EndFunc
    
Func Enableperm($file)
    $Folder = ReturnFolder($file,$sNameConvFile)
    Return $Folder
    
EndFunc

;~ Title:           ReturnFolder
;~ Description:     Returns the Target Folder name given an OFOID.
Func ReturnFolder($ID,$file )
    $ilinecount = _FileCountLines($file)
    $iStringPos = 0
    for $x = 1 to $ilinecount
        $sLineFeed= FileReadLine($file,$x)
        $iStringPos = StringInStr($sLineFeed,$ID)
        $iDlmPos = StringInStr($sLineFeed,"=")+1
        if $iStringPos<>0 Then
            return StringMid($sLineFeed,$iDlmPos)
        EndIf
    Next
    if $iStringPos=0 Then
        return "not found"
    EndIf
EndFunc
Edited by blademonkey

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites
Siao

What version of Autoit?

FileReadLine, if you're using v3.2.4.9 or earlier. Upgrade to the latest or use workaround described in the link.

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites
blademonkey

What version of Autoit?

FileReadLine, if you're using v3.2.4.9 or earlier. Upgrade to the latest or use workaround described in the link.

Thanks, downloading it now and updating.

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites
blademonkey

Thanks, that worked like a charm. I was gonna pull my hair out.

made my day. :)


---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×