From: skodak <skodak>
Date: Wed, 10 Oct 2007 08:43:25 +0000 (+0000)
Subject: add proper rs_close() into cleanup_contexts() - we have to close even when now record... 
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=3f7d5925989003c6a963b5183d9ecd1cf2e3cd39;p=moodle.git

add proper rs_close() into cleanup_contexts() - we have to close even when now records returned
---

diff --git a/lib/accesslib.php b/lib/accesslib.php
index 765851eea5..966518d9eb 100755
--- a/lib/accesslib.php
+++ b/lib/accesslib.php
@@ -2442,20 +2442,22 @@ function cleanup_contexts() {
                 ON c.instanceid = t.id
               WHERE t.id IS NULL AND c.contextlevel = " . CONTEXT_GROUP . "
            ";
-    $rs = get_recordset_sql($sql);
-    if ($rs->RecordCount()) {
-        begin_sql();
-        $tx = true;
-        while ($tx && $ctx = rs_fetch_next_record($rs)) {
-            $tx = $tx && delete_context($ctx->level, $ctx->instanceid);
+    if ($rs = get_recordset_sql($sql)) {
+        if ($rs->RecordCount()) {
+            begin_sql();
+            $tx = true;
+            while ($tx && $ctx = rs_fetch_next_record($rs)) {
+                $tx = $tx && delete_context($ctx->level, $ctx->instanceid);
+            }
+            rs_close($rs);
+            if ($tx) {
+                commit_sql();
+                return true;
+            }
+            rollback_sql();
+            return false;
         }
         rs_close($rs);
-        if ($tx) {
-            commit_sql();
-            return true;
-        }
-        rollback_sql();
-        return false;
     }
     return true;
 }