[GRASS-SVN] r57595 - in grass/trunk: include/defs lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Sep 5 06:45:32 PDT 2013
Author: huhabla
Date: 2013-09-05 06:45:32 -0700 (Thu, 05 Sep 2013)
New Revision: 57595
Modified:
grass/trunk/include/defs/gis.h
grass/trunk/lib/gis/ilist.c
Log:
Fixed potential memory leak in integer list init, added new and free ilist functions.
Modified: grass/trunk/include/defs/gis.h
===================================================================
--- grass/trunk/include/defs/gis.h 2013-09-05 03:23:21 UTC (rev 57594)
+++ grass/trunk/include/defs/gis.h 2013-09-05 13:45:32 UTC (rev 57595)
@@ -321,6 +321,8 @@
/* ilist.c */
void G_init_ilist(struct ilist *);
+void G_free_ilist(struct ilist *);
+struct ilist * G_new_ilist();
void G_ilist_add(struct ilist *, int);
/* intersect.c */
Modified: grass/trunk/lib/gis/ilist.c
===================================================================
--- grass/trunk/lib/gis/ilist.c 2013-09-05 03:23:21 UTC (rev 57594)
+++ grass/trunk/lib/gis/ilist.c 2013-09-05 13:45:32 UTC (rev 57595)
@@ -18,14 +18,46 @@
#include <stdlib.h>
#include <grass/gis.h>
+/**
+ * \brief Free allocated memory of an integer list
+ *
+ * \param list The pointer to an integer list
+ *
+ * */
+void G_free_ilist(struct ilist *list)
+{
+ if(list->value)
+ G_free(list->value);
+ G_free(list);
+}
+
+/**
+ * \brief Return a new integer list.
+ *
+ * G_fatal_error() will be invoked by the
+ * allocation function.
+ *
+ * \return list The pointer to a new allocated integer list
+ *
+ * */
+struct ilist * G_new_ilist()
+{
+ struct ilist *l = G_malloc(sizeof(struct ilist));
+ l->value = NULL;
+ G_init_ilist(l);
+ return l;
+}
+
/**
- * Init an integer list
+ * \brief Init an integer list and free allocated memory
*
* \param list The pointer to an integer list
*
* */
void G_init_ilist(struct ilist *list)
{
+ if(list->value)
+ G_free(list->value);
list->value = NULL;
list->n_values = 0;
list->alloc_values = 0;
More information about the grass-commit
mailing list