Sfoglia il codice sorgente

HPCC-8254 Ensure child datasets are freed up by compound read activities

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 12 anni fa
parent
commit
16d6c4eafe
1 ha cambiato i file con 18 aggiunte e 1 eliminazioni
  1. 18 1
      ecl/hqlcpp/hqlsource.cpp

+ 18 - 1
ecl/hqlcpp/hqlsource.cpp

@@ -1359,7 +1359,24 @@ void SourceBuilder::buildTransformElements(BuildCtx & ctx, IHqlExpression * expr
                     if (!returnIfFilterFails)
                         translator.buildFilter(ctx, test);
                     else
-                        translator.buildFilteredReturn(ctx, test, failedFilterValue);
+                    {
+                        LinkedHqlExpr mismatchReturnValue = failedFilterValue;
+                        //If the output row has already been generated, then returning at this point will leak any
+                        //child datasets. To avoid that we explicitly call the destructor on the output row.
+                        if (recordRequiresDestructor(expr->queryRecord()))
+                        {
+                            if (lastTransformer && lastTransformer->queryNormalizedSelector() == expr->queryNormalizedSelector())
+                            {
+                                StringBuffer s;
+                                translator.buildMetaForRecord(s, expr->queryRecord());
+                                s.append(".destruct(crSelf.row())");
+                                OwnedHqlExpr cleanupAction = createQuoted(s.str(), makeVoidType());
+                                //Create a compound expression (destroy-old, return-value)
+                                mismatchReturnValue.setown(createCompound(LINK(cleanupAction), LINK(mismatchReturnValue)));
+                            }
+                        }
+                        translator.buildFilteredReturn(ctx, test, mismatchReturnValue);
+                    }
                 }
             }
         }