[Groonga-commit] groonga/groonga at 032255a [master] ii: fix memory leak on update error

Back to archive index
Kouhei Sutou null+****@clear*****
Mon Jan 21 11:20:47 JST 2019


Kouhei Sutou	2019-01-21 11:20:47 +0900 (Mon, 21 Jan 2019)

  Revision: 032255a1b48481aae7046816bc0230051397a898
  https://github.com/groonga/groonga/commit/032255a1b48481aae7046816bc0230051397a898

  Message:
    ii: fix memory leak on update error

  Modified files:
    lib/ii.c

  Modified: lib/ii.c (+14 -4)
===================================================================
--- lib/ii.c    2019-01-21 11:08:22 +0900 (1a7340fb9)
+++ lib/ii.c    2019-01-21 11:20:47 +0900 (f5539de86)
@@ -7377,7 +7377,6 @@ grn_ii_column_update(grn_ctx *ctx, grn_ii *ii, grn_id rid, unsigned int section,
       } else {
         grn_ii_delete_one(ctx, ii, *tp, *u, n);
       }
-      grn_ii_updspec_close(ctx, *u);
       if (ctx->rc != GRN_SUCCESS) {
         break;
       }
@@ -7387,7 +7386,6 @@ grn_ii_column_update(grn_ctx *ctx, grn_ii *ii, grn_id rid, unsigned int section,
     grn_hash *n = (grn_hash *)new;
     GRN_HASH_EACH(ctx, n, id, &tp, NULL, &u, {
       grn_ii_update_one(ctx, ii, *tp, *u, n);
-      grn_ii_updspec_close(ctx, *u);
       if (ctx->rc != GRN_SUCCESS) {
         break;
       }
@@ -7399,8 +7397,20 @@ grn_ii_column_update(grn_ctx *ctx, grn_ii *ii, grn_id rid, unsigned int section,
   }
 exit :
   grn_io_unlock(ii->seg);
-  if (old && old != oldvalue) { grn_obj_close(ctx, old); }
-  if (new && new != newvalue) { grn_obj_close(ctx, new); }
+  if (old) {
+    grn_hash *o = (grn_hash *)old;
+    GRN_HASH_EACH(ctx, o, id, &tp, NULL, &u, {
+      grn_ii_updspec_close(ctx, *u);
+    });
+    if (old != oldvalue) { grn_obj_close(ctx, old); }
+  }
+  if (new) {
+    grn_hash *n = (grn_hash *)new;
+    GRN_HASH_EACH(ctx, n, id, &tp, NULL, &u, {
+      grn_ii_updspec_close(ctx, *u);
+    });
+    if (new != newvalue) { grn_obj_close(ctx, new); }
+  }
   return ctx->rc;
 }
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190121/d8320939/attachment-0001.html>


More information about the Groonga-commit mailing list
Back to archive index