[vala] codegen: Fix leak when destroying null terminated arrays
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Fix leak when destroying null terminated arrays
- Date: Sun, 27 Mar 2011 15:04:42 +0000 (UTC)
commit d314806f973a06d20c4dde006348279d86bbaf03
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 b23a08d..4ac24db 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2906,7 +2906,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"));
@@ -2914,7 +2914,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) {
@@ -2926,15 +2926,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]