diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php
index <HASH>..<HASH> 100644
--- a/lib/grade/grade_category.php
+++ b/lib/grade/grade_category.php
@@ -377,6 +377,7 @@ class grade_category extends grade_object {
                 }
                 $this->aggregate_grades($prevuser, $items, $grade_values, $oldgrade, $excluded);//the last one
             }
+            rs_close($rs);
         }
 
         return true;
diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php
index <HASH>..<HASH> 100644
--- a/lib/grade/grade_item.php
+++ b/lib/grade/grade_item.php
@@ -629,6 +629,7 @@ class grade_item extends grade_object {
                     }
                 }
             }
+            rs_close($rs);
         }
 
         return $result;
@@ -1430,6 +1431,7 @@ class grade_item extends grade_object {
                     $return = false;
                 }
             }
+            rs_close($rs);
         }
 
         return $return;
added proper rs_close($rs)