[vala/emit-let: 4/8] codegen: Fix leak when destroying null terminated arrays



commit bed62571f62f36fa5337e53c714b2b7f980b89b3
Author: Luca Bruno <lucabru src gnome org>
Date:   Wed Mar 16 14:27:07 2011 +0100

    codegen: Fix leak when destroying null terminated arrays

 codegen/valaccodebasemodule.vala |   24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 7b00c6c..fe12da3 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2902,7 +2902,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 				ccall.add_argument (new CCodeConstant ("TRUE"));
 			} else if (type is ArrayType) {
 				var array_type = (ArrayType) type;
-				if (requires_destroy (array_type.element_type) && !variable.no_array_length) {
+				if (requires_destroy (array_type.element_type)) {
 					CCodeExpression csizeexpr = null;
 					if (variable.array_null_terminated) {
 						var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length"));
@@ -2910,7 +2910,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 						csizeexpr = len_call;
 					} else if (variable.has_array_length_cexpr) {
 						csizeexpr = new CCodeConstant (variable.get_array_length_cexpr ());
-					} else {
+					} else if (!variable.no_array_length) {
 						bool first = true;
 						for (int dim = 1; dim <= array_type.rank; dim++) {
 							if (first) {
@@ -2922,15 +2922,17 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 						}
 					}
 
-					var st = array_type.element_type.data_type as Struct;
-					if (st != null && !array_type.element_type.nullable) {
-						ccall.call = new CCodeIdentifier (append_struct_array_free (st));
-						ccall.add_argument (csizeexpr);
-					} else {
-						requires_array_free = true;
-						ccall.call = new CCodeIdentifier ("_vala_array_free");
-						ccall.add_argument (csizeexpr);
-						ccall.add_argument (new CCodeCastExpression (get_destroy_func_expression (array_type.element_type), "GDestroyNotify"));
+					if (csizeexpr != null) {
+						var st = array_type.element_type.data_type as Struct;
+						if (st != null && !array_type.element_type.nullable) {
+							ccall.call = new CCodeIdentifier (append_struct_array_free (st));
+							ccall.add_argument (csizeexpr);
+						} else {
+							requires_array_free = true;
+							ccall.call = new CCodeIdentifier ("_vala_array_free");
+							ccall.add_argument (csizeexpr);
+							ccall.add_argument (new CCodeCastExpression (get_destroy_func_expression (array_type.element_type), "GDestroyNotify"));
+						}
 					}
 				}
 			}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]