[Pkg-octave-devel] Bug#541433: octave-sockets: memory leak
Package: octave-sockets
Version: 1.0.4-3
Severity: important
There are two memory leaks in sockets.cc
The first one is a new[] which is paired with delete and not delete[].
The second one has a new[] but no delete[].
I suggest a patch which is attached.
Thanks,
Paul
-- System Information:
Debian Release: 5.0.2
APT prefers stable
APT policy: (500, 'stable')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.26-2-amd64 (SMP w/4 CPU cores)
Locale: LANG=sv_SE.UTF-8, LC_CTYPE=sv_SE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages octave-sockets depends on:
ii libatlas3gf-base [libl 3.6.0-22 Automatically Tuned Linear Algebra
ii libblas3gf [libblas.so 1.2-2 Basic Linear Algebra Subroutines 3
ii libc6 2.7-18 GNU C Library: Shared libraries
ii libfftw3-3 3.1.2-3.1 library for computing Fast Fourier
ii libgcc1 1:4.3.2-1.1 GCC support library
ii libgfortran3 4.3.2-1.1 Runtime library for GNU Fortran ap
ii libhdf5-serial-1.6.6-0 1.6.6-4 Hierarchical Data Format 5 (HDF5)
ii liblapack3gf [liblapac 3.1.1-1 library of linear algebra routines
ii libncurses5 5.7+20081213-1 shared libraries for terminal hand
ii libreadline5 5.2-3.1 GNU readline and history libraries
ii libstdc++6 4.3.2-1.1 The GNU Standard C++ Library v3
ii octave3.0 1:3.0.1-6lenny3 GNU Octave language for numerical
ii zlib1g 1:1.2.3.3.dfsg-12 compression library - runtime
octave-sockets recommends no packages.
octave-sockets suggests no packages.
-- no debconf information
--- sockets.cc.debian-1.0.4-3 2009-08-14 08:11:38.000000000 +0200
+++ sockets.cc 2009-08-14 08:14:23.000000000 +0200
@@ -528,7 +528,7 @@ DEFUN_DLD(send,args,nargout, \
for ( int i = 0 ; i < d1.length() ; i++ )
buf[i] = (unsigned char)d1(i);
retval = ::send( s->get_sock_fd(), (const char*)buf, data.byte_size(), 0 );
- delete buf;
+ delete[] buf;
}
else
{
@@ -543,7 +543,8 @@ DEFUN_DLD(send,args,nargout, \
// function to receive data over a socket
DEFUN_DLD(recv,args,nargout, \
"recv(octave_socket,int)\nSee the send() man pages. This will only allow the" \
- " user to receive uint8 arrays or strings")
+ " user to receive uint8 arrays or strings" \
+"\n pauls version")
{
int retval = 0;
int flags = 0;
@@ -571,11 +572,14 @@ DEFUN_DLD(recv,args,nargout, \
}
else
{
- error("connect: expecting a octave_socket or integer");
+ error("recv: expecting a octave_socket or integer");
return octave_value(-1);
}
long len = args(1).int_value();
+ if(len<0)
+ error("recv: negative receive length requested");
+
unsigned char* buf = new unsigned char[ len ];
#ifndef __WIN32__
retval = ::recv( s->get_sock_fd(), buf, len, flags );
@@ -588,6 +592,8 @@ DEFUN_DLD(recv,args,nargout, \
for ( int i = 0 ; i < retval ; i++ )
return_buf(0,i) = buf[i];
+ delete[] buf;
+
octave_value in_buf(return_buf);
octave_value out_buf;
OCTAVE_TYPE_CONV( in_buf, out_buf, uint8 );
Reply to: