Help finding a leak

A

awertyui

I'm having trouble finding out why my program leaks like the titanic.
The program works fine but if you run it for a few mins it will use up
all the memory. Every function that calls dlls through ruby dl seem to
leak. I must be doing something stupid but I can't figure out what it
is.
I made a small program which leaks when it calls peekMessage over and
over again. You can see it take up memory in the task manager until its
all gone.
You can call getConsoleWindow over and over again and that leaks too.


require 'dl/import'
require 'dl/struct'
require 'dl/types'


module MyWin32
extend DL::Importable
dlload 'user32.dll' , 'kernel32.dll'

typealias "WPARAM", "UINT"
typealias "LPARAM", "UINT"
typealias "HINSTANCE", "UINT"
typealias "HMENU","UINT"


MSG = struct [
"HWND hwnd",
"UINT message",
"UINT wParam",
"UINT lParam",
"DWORD time",
"ULONG pt_x",
"ULONG pt_y"
]

typealias "LPMSG","MSG*"
extern 'HWND GetConsoleWindow()'
extern 'BOOL PeekMessage(LPMSG,HWND,UINT,UINT,UINT)'
extern 'UINT GetMessage(LPMSG,HWND,UINT,UINT)'

end



msgStruct2 = MyWin32::MSG.malloc
windowHandle = MyWin32.getConsoleWindow()
timer = Time.now
count = 0
while true
#windowHandle = MyWin32.getConsoleWindow() #This leaks too
MyWin32.peekMessage(msgStruct2,windowHandle,0,0,0x0000)
if(Time.now - timer) > 30 #run for 30 sec

break

end
count += 1
end
puts "COUNT: #{count.to_s}"

puts "done press enter"
line = gets("\n")
 
T

Takaaki Tateishi

I'm having trouble finding out why my program leaks like the titanic.
The program works fine but if you run it for a few mins it will use up
all the memory.

To be sure, the program leaks, but I won't be able to fix it soon.
You can use Ruby/DL2 instead. It will work fine.

Thanks,
 
A

awertyui

Thanks for your help everything almost works now. The only problem I
have now is that it seems that there is no to_ptr method in ruby/dl2 so
how do I pass a ptr to a function that takes a string and changes the
string? I tried using CPtr but I'm not to sure how to use it.

here is the DL extern setup for the function

extern 'ATOM GlobalGetAtomName(ATOM,PVOID,int)'

Here is what I had and it worked with the old DL.

tmp = "".ljust(256,"NO-CHANGE")
z1 = tmp.to_ptr
if(msg == @MessageRequestComplete)
MyWin32.globalGetAtomName(lparam,z1,255)
puts z1.to_s
end


Here is what im trying with DL2

tmp = "".ljust(256,"NO-CHANGE")
if(msg == @MessageRequestComplete)
MyWin32.GlobalGetAtomName(lparam,tmp,255)
puts tmp
end
 
M

moinker

I'm an idiot. I was calling it with the wrong parameter. Everything
works now. Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top