Subject: | Memory leak in _ping_iterator_get_hostname() |
It seems, that Perl's GC is not taking care of memory allocated for the
buffer in _ping_iterator_get_hostname() by malloc() function call.
While pointer to the buffer is returned from the function, it is never
freed and thus a memory leak occurs.
Please see the patch attached that seem to fix the problem.
My environment:
Perl 5.10.0
Linux 2.6.25.2
Debian testing/unstable
Subject: | net-oping.diff |
diff -urN a/Oping.xs b/Oping.xs
--- a/Oping.xs 2008-01-26 13:59:18.000000000 +0100
+++ b/Oping.xs 2008-06-24 18:40:03.000000000 +0200
@@ -105,16 +105,14 @@
OUTPUT:
RETVAL
-char *
+void
_ping_iterator_get_hostname (iter)
pingobj_iter_t *iter
- CODE:
+ PPCODE:
char *buffer;
size_t buffer_size;
int status;
- RETVAL = NULL;
-
do {
buffer = NULL;
buffer_size = 0;
@@ -135,10 +133,10 @@
if (status != 0)
break;
- RETVAL = buffer;
+ XPUSHs(sv_2mortal(newSVpvn(buffer,buffer_size)));
+ free(buffer);
+
} while (0);
- OUTPUT:
- RETVAL
const char *
_ping_get_error (obj)