Browse Source

Fix invalid pointer access in generated code

A call to an external function that returned a row (e.g., FROMXML)
in a conditional context could cause the result to be aliased, and
then go out of scope, leading to an invalid pointer reference.

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 13 years ago
parent
commit
ff373da7dc
1 changed files with 13 additions and 2 deletions
  1. 13 2
      ecl/hqlcpp/hqlcpp.cpp

+ 13 - 2
ecl/hqlcpp/hqlcpp.cpp

@@ -4058,6 +4058,19 @@ IHqlExpression * HqlCppTranslator::createWrapperTemp(BuildCtx & ctx, ITypeInfo *
     Owned<ITypeInfo> declType = makeWrapperModifier(rawType.getClear());
     declType.setown(makeModifier(declType.getClear(), modifier));
 
+    switch (declType->getTypeCode())
+    {
+    case type_set:  //needed if we have sets with link counted elements
+    case type_row:
+    case type_array:
+    case type_table:
+    case type_groupedtable:
+        //Ensure row and dataset temporaries are active throughout a function, so pointers to the row
+        //or rows within a dataset remain valid (e.g., outside conditions).
+        if ((modifier != typemod_member) && ctx.queryMatchExpr(queryConditionalRowMarker()))
+            ctx.setNextPriority(BuildCtx::OutermostScopePrio);
+        break;
+    }
     return ctx.getTempDeclare(declType, NULL);
 }
 
@@ -4169,8 +4182,6 @@ void HqlCppTranslator::createTempFor(BuildCtx & ctx, ITypeInfo * _exprType, CHql
     case type_groupedtable:
         {
             OwnedITypeInfo lenType = makeModifier(LINK(sizetType), modifier);
-            if ((modifier != typemod_member) && ctx.queryMatchExpr(queryConditionalRowMarker()))
-                ctx.setNextPriority(BuildCtx::OutermostScopePrio);
             target.expr.setown(createWrapperTemp(ctx, exprType, modifier));
             if (isArrayRowset(exprType))
             {