зеркало из https://github.com/github/ruby.git
udpsocket.c: memory leaks
* ext/socket/udpsocket.c (udp_connect, udp_bind, udp_send): fix memory leaks at closed socket. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
24e5e37410
Коммит
38e6235235
|
@ -1,3 +1,8 @@
|
|||
Sat Oct 10 08:52:21 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ext/socket/udpsocket.c (udp_connect, udp_bind, udp_send): fix
|
||||
memory leaks at closed socket.
|
||||
|
||||
Fri Oct 9 17:29:07 2015 Shugo Maeda <shugo@ruby-lang.org>
|
||||
|
||||
* lib/net/ftp.rb (parse257): refactor.
|
||||
|
|
|
@ -84,8 +84,8 @@ udp_connect(VALUE sock, VALUE host, VALUE port)
|
|||
struct udp_arg arg;
|
||||
VALUE ret;
|
||||
|
||||
arg.res = rsock_addrinfo(host, port, SOCK_DGRAM, 0);
|
||||
GetOpenFile(sock, fptr);
|
||||
arg.res = rsock_addrinfo(host, port, SOCK_DGRAM, 0);
|
||||
arg.fd = fptr->fd;
|
||||
ret = rb_ensure(udp_connect_internal, (VALUE)&arg,
|
||||
rsock_freeaddrinfo, (VALUE)arg.res);
|
||||
|
@ -112,8 +112,8 @@ udp_bind(VALUE sock, VALUE host, VALUE port)
|
|||
struct rb_addrinfo *res0;
|
||||
struct addrinfo *res;
|
||||
|
||||
res0 = rsock_addrinfo(host, port, SOCK_DGRAM, 0);
|
||||
GetOpenFile(sock, fptr);
|
||||
res0 = rsock_addrinfo(host, port, SOCK_DGRAM, 0);
|
||||
for (res = res0->ai; res; res = res->ai_next) {
|
||||
if (bind(fptr->fd, res->ai_addr, res->ai_addrlen) < 0) {
|
||||
continue;
|
||||
|
@ -166,8 +166,8 @@ udp_send(int argc, VALUE *argv, VALUE sock)
|
|||
rb_scan_args(argc, argv, "4", &arg.mesg, &flags, &host, &port);
|
||||
|
||||
StringValue(arg.mesg);
|
||||
res0 = rsock_addrinfo(host, port, SOCK_DGRAM, 0);
|
||||
GetOpenFile(sock, fptr);
|
||||
res0 = rsock_addrinfo(host, port, SOCK_DGRAM, 0);
|
||||
arg.fd = fptr->fd;
|
||||
arg.flags = NUM2INT(flags);
|
||||
for (res = res0->ai; res; res = res->ai_next) {
|
||||
|
|
|
@ -69,4 +69,31 @@ class TestSocket_UDPSocket < Test::Unit::TestCase
|
|||
ensure
|
||||
u.close if u
|
||||
end
|
||||
|
||||
def test_bind_no_memory_leak
|
||||
assert_no_memory_leak(["-rsocket"], <<-"end;", <<-"end;", rss: true)
|
||||
s = UDPSocket.new
|
||||
s.close
|
||||
end;
|
||||
100_000.times {begin s.bind("127.0.0.1", 1) rescue IOError; end}
|
||||
end;
|
||||
end
|
||||
|
||||
def test_connect_no_memory_leak
|
||||
assert_no_memory_leak(["-rsocket"], <<-"end;", <<-"end;", rss: true)
|
||||
s = UDPSocket.new
|
||||
s.close
|
||||
end;
|
||||
100_000.times {begin s.connect("127.0.0.1", 1) rescue IOError; end}
|
||||
end;
|
||||
end
|
||||
|
||||
def test_send_no_memory_leak
|
||||
assert_no_memory_leak(["-rsocket"], <<-"end;", <<-"end;", rss: true)
|
||||
s = UDPSocket.new
|
||||
s.close
|
||||
end;
|
||||
100_000.times {begin s.send("\0"*100, 0, "127.0.0.1", 1) rescue IOError; end}
|
||||
end;
|
||||
end
|
||||
end if defined?(UDPSocket)
|
||||
|
|
Загрузка…
Ссылка в новой задаче