forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Memory Leak

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
chucks0
Newbie


Joined: 08 Jun 2002
Posts: 23

PostPosted: Mon Nov 10, 2003 8:39 pm    Post subject: Memory Leak Reply with quote

I am building a process monitor / killer that will monitor the system for forbidden applications and kill them if found. The code is:

Code:
OPTION ERRORTRAP,ErrorHandler

#define command,CheckFiles
#define command,GetForbidden
#define command,GetProcs
#define command,KillProcs


CheckFiles
GetForbidden
:CheckProcs
  GetProcs
  KillProcs
  WAIT 30
  LIST CLOSE,5
GOTO CheckProcs
EXIT




#-----------------------------------------------------------------------------#
#  CheckFiles - Command to check for existance of required files.             #
#-----------------------------------------------------------------------------#
:CheckFiles
  IF @NOT(@BOTH(@FILE(@SHORTNAME(@PATH(%0))@NAME(%0).all),@FILE(@SHORTNAME(@PATH(%0))@NAME(%0).stu)))
    STOP
  END
EXIT


#-----------------------------------------------------------------------------#
#  GetForbidden - Command to create list of denied applications.              #
#-----------------------------------------------------------------------------#
:GetForbidden
  LIST CREATE,1
  LIST LOADFILE,1,@SHORTNAME(@PATH(%0))@NAME(%0).all
  IF @GREATER(@POS(STUDENTS,@REGREAD(LOCAL,SYSTEM\CurrentControlSet\Services\NetwareWorkstation\Parameters\Trees,RICHLAND2)),0)
    LIST CREATE,2
    LIST LOADFILE,2,@SHORTNAME(@PATH(%0))@NAME(%0).stu
    LIST APPEND,1,2
    LIST CLOSE,2
  END
  %i = 0
  WHILE @GREATER(@COUNT(1),%i)
    LIST SEEK,1,%i
    PARSE "%%ProcName;%%Desc",@ITEM(1)
    LIST PUT,1,%%ProcName
    %i = @SUCC(%i)
  WEND
EXIT


#-----------------------------------------------------------------------------#
#  GetProcs - Command to create list of all running processes.                #
#-----------------------------------------------------------------------------#
:GetProcs
  LIST CREATE,5
  LIST TASKLIST,5,NI
  LIST CREATE,9
  %i = 0
  WHILE @GREATER(@COUNT(5),%i)
    LIST SEEK,5,%i
    PARSE "%%ProcName;%%ProcID",@ITEM(5)
    LIST MODULES,9,%%ProcID
    LIST PUT,5,%%ProcName|@VERINFO(@ITEM(9,0),N)|%%ProcID
    LIST CLEAR,9
    %i = @SUCC(%i)
  WEND
  LIST CLOSE,9
EXIT


#-----------------------------------------------------------------------------#
#  KillProcs - Command to kill running processes that are not allowed.        #
#-----------------------------------------------------------------------------#
:KillProcs
  %i = 0
  WHILE @GREATER(@COUNT(5),%i)
    LIST SEEK,1,0
    LIST SEEK,5,%i
   PARSE "%%ProcName;%%OrigName;%%ProcID",@ITEM(5)
   IF @MATCH(1,%%ProcName)
     KILLTASK %%ProcID
   ELSIF @MATCH(1,%%OrigName)
     KILLTASK %%ProcID
   END
   %i = @SUCC(%i)
  WEND
EXIT


:ErrorHandler
  STOP


The application runs great except that it appears to consume more and more ram during each polling cycle. If you wish to test the code, just save the script as taskmon.dsc and create two files called taskmon.stu and taskmon.all in the same directory as the script. The files should contain a list of applications to be monitored in the format:

notepad.exe|Text Editor

with one application on each line. I can't locate where the problem might be.

Thanks,
Charles
Back to top
View user's profile Send private message
chucks0
Newbie


Joined: 08 Jun 2002
Posts: 23

PostPosted: Tue Nov 11, 2003 3:56 am    Post subject: Reply with quote

Doing some testing I have narrowed down the memory leak to the following code in the GetProcs command:

Code:
    LIST MODULES,9,%%ProcID
    LIST PUT,5,%%ProcName|@VERINFO(@ITEM(9,0),N)|%%ProcID
    LIST CLEAR,9


The purpose of this code is to trace back the running processes to their original location and then reading the "orignal name" attribute from the file. This way I can prevent students from just renaming the exe file. When I rem out this section, the memory leak goes away.

Any ideas?
Back to top
View user's profile Send private message
CodeScript
Moderator Team


Joined: 08 Jun 2003
Posts: 1060
Location: India

PostPosted: Tue Nov 11, 2003 4:02 am    Post subject: Reply with quote

I think it is a problem with memory allocated to local variables.
http://forum.vdsworld.com/viewtopic.php?t=2081
I haven't tested if your code has additional flaws.
If you have a continuous/multiple loops using local varaibles this occurs.
I don't kanow if this is fixed in the update to be relaesed. Rolling Eyes

_________________
Regards
- CodeScript
Arrow Give your application a professional look with the VDSGUI Extension
Back to top
View user's profile Send private message Visit poster's website
chucks0
Newbie


Joined: 08 Jun 2002
Posts: 23

PostPosted: Tue Nov 11, 2003 4:13 am    Post subject: Reply with quote

I had seen that post and changed all of my defined functions to gosub calls but the memory leak remained. It seems to be related to creating and clearing the lists over and over.
Back to top
View user's profile Send private message
chucks0
Newbie


Joined: 08 Jun 2002
Posts: 23

PostPosted: Tue Nov 11, 2003 4:26 am    Post subject: Reply with quote

Here is a good script to show what is happening. Just compile it and run the resulting exe.

Code:
LIST CREATE,1
:Loop
  LIST TASKLIST,1,NI
  LIST CLEAR,1
  WAIT .050
GOTO Loop


OR

Code:
:Loop
  LIST CREATE,1
  LIST TASKLIST,1,NI
  LIST CLOSE,1
  WAIT .050
GOTO Loop


You'll see in taskmgr that the memory usage climbs and climbs.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Bug Reports All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group