[gnumeric] SHEET: fix leak.



commit b6929125fca6969cfa1b56bdc465c3cdbedc1dfa
Author: Morten Welinder <terra gnome org>
Date:   Sat May 21 22:07:57 2011 -0400

    SHEET: fix leak.

 NEWS                          |    3 +++
 plugins/fn-lookup/ChangeLog   |    4 ++++
 plugins/fn-lookup/functions.c |   25 +++++++++++--------------
 3 files changed, 18 insertions(+), 14 deletions(-)
---
diff --git a/NEWS b/NEWS
index bbcdfae..1453305 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
 Gnumeric 1.10.16
 
+Morten:
+	* Fix leaks in SHEET.  [#650761]
+
 --------------------------------------------------------------------------
 Gnumeric 1.10.15
 
diff --git a/plugins/fn-lookup/ChangeLog b/plugins/fn-lookup/ChangeLog
index cb315f4..ce7e4a8 100644
--- a/plugins/fn-lookup/ChangeLog
+++ b/plugins/fn-lookup/ChangeLog
@@ -1,3 +1,7 @@
+2011-05-21  Morten Welinder  <terra gnome org>
+
+	* functions.c (gnumeric_sheet): Simplify.  Fixes #650761.
+
 2011-05-21  Morten Welinder <terra gnome org>
 
 	* Release 1.10.15
diff --git a/plugins/fn-lookup/functions.c b/plugins/fn-lookup/functions.c
index 31e4f94..630e218 100644
--- a/plugins/fn-lookup/functions.c
+++ b/plugins/fn-lookup/functions.c
@@ -1618,37 +1618,34 @@ gnumeric_sheet (GnmFuncEvalInfo *ei, GnmValue const * const *args)
 {
 	Workbook const *wb = ei->pos->sheet->workbook;
 	GnmValue const *v = args[0];
+	int n;
 
 	if(v) {
 		if (v->type == VALUE_CELLRANGE) {
 			GnmRangeRef const *r = &v->v_range.cell;
 			int a, b;
 
-			a = g_slist_index (workbook_sheets (wb), r->a.sheet);
-			b = g_slist_index (workbook_sheets (wb), r->b.sheet);
+			a = r->a.sheet ? r->a.sheet->index_in_wb : -1;
+			b = r->b.sheet ? r->b.sheet->index_in_wb : -1;
 
 			if (a == -1 && b == -1)
-				return value_new_int (1 + g_slist_index
-						      (workbook_sheets (wb),
-						       ei->pos->sheet));
-			else if (a == b || (a * b) < 0)
-				return value_new_int (1 + ((a < b) ? b : a));
+				n = ei->pos->sheet->index_in_wb;
+			else if (a == b || a * b < 0)
+				n = MAX (a,b);
 			else
 				return value_new_error_NUM (ei->pos);
 		} else if (v->type == VALUE_STRING) {
 			Sheet *sheet = workbook_sheet_by_name
 				(wb, value_peek_string (v));
-			if (sheet == NULL)
+			if (!sheet)
 				return value_new_error_NUM (ei->pos);
-			else
-				return value_new_int
-					(1 + g_slist_index (workbook_sheets (wb),
-							    sheet));
+			n = sheet->index_in_wb;
 		} else
 			return value_new_error_VALUE (ei->pos);
 	} else
-		return value_new_int (1 + g_slist_index (workbook_sheets (wb),
-							 ei->pos->sheet));
+		n = ei->pos->sheet->index_in_wb;
+
+	return value_new_int (1 + n);
 }
 /***************************************************************************/
 



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