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

[augeas-devel] [PATCH 05/16] * src/lens.c (free_lens): free recursive lenses



From: David Lutterkort <lutter redhat com>

---
 src/lens.c |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/lens.c b/src/lens.c
index 85af37b..3aa6bf3 100644
--- a/src/lens.c
+++ b/src/lens.c
@@ -668,10 +668,6 @@ void free_lens(struct lens *lens) {
         return;
     assert(lens->ref == 0);
 
-    unref(lens->info, info);
-    for (int t=0; t < ntypes; t++)
-        unref(ltype(lens, t), regexp);
-
     switch (lens->tag) {
     case L_DEL:
         unref(lens->regexp, regexp);
@@ -697,10 +693,23 @@ void free_lens(struct lens *lens) {
             unref(lens->children[i], lens);
         free(lens->children);
         break;
+    case L_REC:
+        if (lens->ref != REF_MAX) {
+            /* Break unbounded recursion */
+            lens->ref = REF_MAX;
+            unref(lens->body, lens);
+        }
+        break;
     default:
         assert(0);
         break;
     }
+
+    for (int t=0; t < ntypes; t++)
+        unref(ltype(lens, t), regexp);
+
+    unref(lens->info, info);
+
     free(lens);
 }
 
-- 
1.6.5.2



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