[Groonga-commit] groonga/groonga at 3b91ce1 [master] plugin: fix a crash bug on multiple DB open case

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Aug 12 17:10:00 JST 2013


Kouhei Sutou	2013-08-12 17:10:00 +0900 (Mon, 12 Aug 2013)

  New Revision: 3b91ce16d97e94d074e806deff78404f470fa4ba
  https://github.com/groonga/groonga/commit/3b91ce16d97e94d074e806deff78404f470fa4ba

  Message:
    plugin: fix a crash bug on multiple DB open case
    
    There are the following two conditions for the crash bug:
    
      * A plugin has two or more normalizers/tokenizers
        (e.g.: groonga-normalizer-mysql) is used.
      * The same database is opened from two or more in a process
        (mroonga use case).
    
    The first database closing closes the plugin even if the rest opened
    database uses the plugin.
    
    [groonga-dev,01596]
    
    Reported by Naoya Murakami. Thanks!!!

  Modified files:
    lib/db.c
    lib/plugin.c
    lib/plugin_in.h

  Modified: lib/db.c (+4 -2)
===================================================================
--- lib/db.c    2013-08-12 15:13:49 +0900 (a5d8c7b)
+++ lib/db.c    2013-08-12 17:10:00 +0900 (ba00fe9)
@@ -551,7 +551,7 @@ grn_proc_create(grn_ctx *ctx, const char *name, int name_size, grn_proc_type typ
 {
   grn_proc *res = NULL;
   grn_id id = GRN_ID_NIL;
-  grn_id range;
+  grn_id range = GRN_ID_NIL;
   int added = 0;
   grn_obj *db;
   const char *path = ctx->impl->plugin_path;
@@ -560,7 +560,9 @@ grn_proc_create(grn_ctx *ctx, const char *name, int name_size, grn_proc_type typ
     return NULL;
   }
   GRN_API_ENTER;
-  range = path ? grn_plugin_get(ctx, path) : GRN_ID_NIL;
+  if (path) {
+    range = grn_plugin_reference(ctx, path);
+  }
   if (name_size < 0) {
     name_size = strlen(name);
   }

  Modified: lib/plugin.c (+17 -22)
===================================================================
--- lib/plugin.c    2013-08-12 15:13:49 +0900 (c239790)
+++ lib/plugin.c    2013-08-12 17:10:00 +0900 (55c6a9f)
@@ -51,9 +51,18 @@ static grn_hash *grn_plugins = NULL;
 #endif
 
 grn_id
-grn_plugin_get(grn_ctx *ctx, const char *filename)
+grn_plugin_reference(grn_ctx *ctx, const char *filename)
 {
-  return grn_hash_get(ctx, grn_plugins, filename, PATHLEN(filename), NULL);
+  grn_id id;
+  grn_plugin **plugin = NULL;
+
+  id = grn_hash_get(ctx, grn_plugins, filename, PATHLEN(filename),
+                    (void **)&plugin);
+  if (plugin) {
+    (*plugin)->refcount++;
+  }
+
+  return id;
 }
 
 const char *
@@ -165,13 +174,6 @@ grn_plugin_initialize(grn_ctx *ctx, grn_plugin *plugin,
   return ctx->rc;
 }
 
-static grn_id
-grn_plugin_find(grn_ctx *ctx, const char *filename, grn_plugin **plugin)
-{
-  return grn_hash_get(ctx, grn_plugins, filename, PATHLEN(filename),
-                      (void **)&plugin);
-}
-
 grn_id
 grn_plugin_open(grn_ctx *ctx, const char *filename)
 {
@@ -179,12 +181,12 @@ grn_plugin_open(grn_ctx *ctx, const char *filename)
   grn_dl dl;
   grn_plugin **plugin = NULL;
 
-  if ((id = grn_plugin_find(ctx, filename, plugin))) {
-    if (plugin && *plugin) {
-      (*plugin)->refcount++;
-    }
+  if ((id = grn_hash_get(ctx, grn_plugins, filename, PATHLEN(filename),
+                         (void **)&plugin))) {
+    (*plugin)->refcount++;
     return id;
   }
+
   if ((dl = grn_dl_open(filename))) {
     if ((id = grn_hash_add(ctx, grn_plugins, filename, PATHLEN(filename),
                            (void **)&plugin, NULL))) {
@@ -307,19 +309,12 @@ grn_plugin_register_by_path(grn_ctx *ctx, const char *path)
   GRN_API_ENTER;
   if (GRN_DB_P(db)) {
     grn_id id;
-    grn_bool opened = GRN_FALSE;
-    id = grn_plugin_find(ctx, path, NULL);
-    if (id == GRN_ID_NIL) {
-      id = grn_plugin_open(ctx, path);
-      opened = GRN_TRUE;
-    }
+    id = grn_plugin_open(ctx, path);
     if (id) {
       ctx->impl->plugin_path = path;
       ctx->rc = grn_plugin_call_register(ctx, id);
       ctx->impl->plugin_path = NULL;
-      if (ctx->rc && opened) {
-        grn_plugin_close(ctx, id);
-      }
+      grn_plugin_close(ctx, id);
     }
   } else {
     ERR(GRN_INVALID_ARGUMENT, "invalid db assigned");

  Modified: lib/plugin_in.h (+1 -1)
===================================================================
--- lib/plugin_in.h    2013-08-12 15:13:49 +0900 (6684da6)
+++ lib/plugin_in.h    2013-08-12 17:10:00 +0900 (6f98308)
@@ -57,7 +57,7 @@ grn_rc grn_plugins_init(void);
 grn_rc grn_plugins_fin(void);
 grn_id grn_plugin_open(grn_ctx *ctx, const char *filename);
 grn_rc grn_plugin_close(grn_ctx *ctx, grn_id id);
-grn_id grn_plugin_get(grn_ctx *ctx, const char *filename);
+grn_id grn_plugin_reference(grn_ctx *ctx, const char *filename);
 const char *grn_plugin_path(grn_ctx *ctx, grn_id id);
 char *grn_plugin_find_path(grn_ctx *ctx, const char *name);
 
-------------- next part --------------
HTML����������������������������...
下載 



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