This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Typemap.xs: avoid leak
authorDavid Mitchell <davem@iabyn.com>
Sat, 27 Apr 2019 14:55:20 +0000 (15:55 +0100)
committerDavid Mitchell <davem@iabyn.com>
Sat, 27 Apr 2019 14:55:20 +0000 (15:55 +0100)
The code was doing Safefree(in[i++]) in a loop,
but Safefree() is a macro which may evaluate its arg multiple times,
causing to i to get multipally incremented and thus skipping over some
items that need freeing.

This module is only used for build and test and isn't isn't installed,
so this fix is for the benefit of smokers rather than end users.

ext/XS-Typemap/Typemap.xs

index 16731b1..1c54d1a 100644 (file)
@@ -203,9 +203,9 @@ XS_unpack_anotherstructPtrPtr(SV *in)
 void
 XS_release_anotherstructPtrPtr(anotherstruct **in)
 {
 void
 XS_release_anotherstructPtrPtr(anotherstruct **in)
 {
-    unsigned int i = 0;
-    while (in[i] != NULL)
-        Safefree(in[i++]);
+    unsigned int i;
+    for (i = 0; in[i] != NULL; i++)
+        Safefree(in[i]);
     Safefree(in);
 }
 
     Safefree(in);
 }