Mantis Bugtracker          
testlink.org

View Revisions: Issue #7009 All Revisions ] Back to Issue ]
Summary 0007009: Blank report pages redux (OutOfMemory when generating reports)
Revision 2015-03-14 07:46 by fman
Description As reported previously in issue 0006965, there is a out of memory while creating test plan reports. We have FOUND what is causing the out of memory and we PROVIDE a fix following a very detailed description of the problem.

After some hours of debugging, we have found that the function "renderTestSpecTreeForPrinting" in the file "print.inc.php" was creating an infinite recursion when the tree node provided had leafs. A simple structure like:

PARENT
|_ LEAF

Would create the problem (no matter how many test cases were associated with it). The problem lies in the representation of the tree node that is provided in the "$node" variable when the function is called from the file "printDocument.php". We have noticed that for some reason one of the array elements (leaf) is a string instead of the expected array (the correct representation of a node). In our case the string was "d8ba8cfb-ca92-4fa5-83c2-551977d405fb". We could trace back the origin of this string to the function "get_subtree" in the file "tree.class.php".
we have applied a improvement in the recursive function that will check if the leaf nodes are arrays, ignoring them if not. This will stop PHP from entering the infinite recursion (in our case it is was always around 3100 indentation levels).

The problematic code is when you do "$node['childNodes']" (line 807 of the "print.inc.php" file) to a string. Since PHP cannot resolve the "childNodes" key, it will return the first character of the string, in our case it was always returning "d" which is the first character of the "d8ba8cfb-ca92-4fa5-83c2-551977d405fb" string. We have attached some logging where you can see the tree structure and the recursion happening until the out of memory.

Follows the patch.

--- a/lib/functions/print.inc.php 2015-03-13 16:38:34.000000000 +0000
+++ b/lib/functions/print.inc.php 2015-03-13 17:51:52.000000000 +0000
@@ -767,7 +767,6 @@
 context['prefix']

 */
-
 function renderTestSpecTreeForPrinting(&$db,&$node,&$options,$env,$context,$tocPrefix,$indentLevel)
 {
   static $tree_mgr;
@@ -810,7 +809,7 @@
     for($idx = 0;$idx < $children_qty ;$idx++)
     {
       $current = $childNodes[$idx];
- if(is_null($current))
+ if(is_null($current) || !is_array($current))
       {
         continue;
       }
Revision 2015-03-13 18:43 by filipse
Description As reported previously in issue 0006965, there is a out of memory while creating test plan reports. We have FOUND what is causing the out of memory and we PROVIDE a fix following a very detailed description of the problem.

After some hours of debugging, we have found that the function "renderTestSpecTreeForPrinting" in the file "print.inc.php" was creating an infinite recursion when the tree node provided had leafs. A simple structure like:

PARENT
|_ LEAF

Would create the problem (no matter how many test cases were associated with it). The problem lies in the representation of the tree node that is provided in the "$node" variable when the function is called from the file "printDocument.php". We have noticed that for some reason one of the array elements (leaf) is a string instead of the expected array (the correct representation of a node). In our case the string was "d8ba8cfb-ca92-4fa5-83c2-551977d405fb". We could trace back the origin of this string to the function "get_subtree" in the file "tree.class.php". Rather than debugging further (left as an exercise for the developer :P), we have applied a improvement in the recursive function that will check if the leaf nodes are arrays, ignoring them if not. This will stop PHP from entering the infinite recursion (in our case it is was always around 3100 indentation levels).

The problematic code is when you do "$node['childNodes']" (line 807 of the "print.inc.php" file) to a string. Since PHP cannot resolve the "childNodes" key, it will return the first character of the string, in our case it was always returning "d" which is the first character of the "d8ba8cfb-ca92-4fa5-83c2-551977d405fb" string. We have attached some logging where you can see the tree structure and the recursion happening until the out of memory.

Follows the patch.

--- a/lib/functions/print.inc.php 2015-03-13 16:38:34.000000000 +0000
+++ b/lib/functions/print.inc.php 2015-03-13 17:51:52.000000000 +0000
@@ -767,7 +767,6 @@
 context['prefix']

 */
-
 function renderTestSpecTreeForPrinting(&$db,&$node,&$options,$env,$context,$tocPrefix,$indentLevel)
 {
   static $tree_mgr;
@@ -810,7 +809,7 @@
     for($idx = 0;$idx < $children_qty ;$idx++)
     {
       $current = $childNodes[$idx];
- if(is_null($current))
+ if(is_null($current) || !is_array($current))
       {
         continue;
       }

Have a nice weekend :)



Copyright © 2000 - 2019 MantisBT Team
Powered by Mantis Bugtracker