[Groonga-commit] pgroonga/pgroonga at ec21237 [master] Add a check for failure case on initialization

Back to archive index

Kouhei Sutou null+****@clear*****
Sun Oct 4 11:17:08 JST 2015


Kouhei Sutou	2015-10-04 11:17:08 +0900 (Sun, 04 Oct 2015)

  New Revision: ec212379660d4a0591329c46058e11fe6411a410
  https://github.com/pgroonga/pgroonga/commit/ec212379660d4a0591329c46058e11fe6411a410

  Message:
    Add a check for failure case on initialization

  Modified files:
    pgroonga.c

  Modified: pgroonga.c (+26 -19)
===================================================================
--- pgroonga.c    2015-10-03 21:57:12 +0900 (e3d692e)
+++ pgroonga.c    2015-10-04 11:17:08 +0900 (220a514)
@@ -188,7 +188,7 @@ PG_FUNCTION_INFO_V1(pgroonga_costestimate);
 PG_FUNCTION_INFO_V1(pgroonga_options);
 
 static grn_ctx grnContext;
-static grn_ctx *ctx = &grnContext;
+static grn_ctx *ctx = NULL;
 static grn_obj buffer;
 static grn_obj pathBuffer;
 static grn_obj ctidBuffer;
@@ -412,22 +412,26 @@ PGrnEnsureDatabase(void)
 static void
 PGrnOnProcExit(int code, Datum arg)
 {
-	grn_obj *db;
-
-	GRN_OBJ_FIN(ctx, &inspectBuffer);
-	GRN_OBJ_FIN(ctx, &footBuffer);
-	GRN_OBJ_FIN(ctx, &bodyBuffer);
-	GRN_OBJ_FIN(ctx, &headBuffer);
-	GRN_OBJ_FIN(ctx, &ctidBuffer);
-	GRN_OBJ_FIN(ctx, &scoreBuffer);
-	GRN_OBJ_FIN(ctx, &pathBuffer);
-	GRN_OBJ_FIN(ctx, &buffer);
-
-	db = grn_ctx_db(ctx);
-	if (db)
-		grn_obj_close(ctx, db);
-
-	grn_ctx_fin(ctx);
+	if (ctx)
+	{
+		grn_obj *db;
+
+		GRN_OBJ_FIN(ctx, &inspectBuffer);
+		GRN_OBJ_FIN(ctx, &footBuffer);
+		GRN_OBJ_FIN(ctx, &bodyBuffer);
+		GRN_OBJ_FIN(ctx, &headBuffer);
+		GRN_OBJ_FIN(ctx, &ctidBuffer);
+		GRN_OBJ_FIN(ctx, &scoreBuffer);
+		GRN_OBJ_FIN(ctx, &pathBuffer);
+		GRN_OBJ_FIN(ctx, &buffer);
+
+		db = grn_ctx_db(ctx);
+		if (db)
+			grn_obj_close(ctx, db);
+
+		grn_ctx_fin(ctx);
+	}
+
 	grn_fin();
 }
 
@@ -555,12 +559,15 @@ _PG_init(void)
 		ereport(ERROR,
 				(errcode(ERRCODE_SYSTEM_ERROR),
 				 errmsg("pgroonga: failed to initialize Groonga")));
-	if (grn_ctx_init(ctx, 0))
+
+	on_proc_exit(PGrnOnProcExit, 0);
+
+	if (grn_ctx_init(&grnContext, 0))
 		ereport(ERROR,
 				(errcode(ERRCODE_SYSTEM_ERROR),
 				 errmsg("pgroonga: failed to initialize Groonga context")));
 
-	on_proc_exit(PGrnOnProcExit, 0);
+	ctx = &grnContext;
 
 	GRN_VOID_INIT(&buffer);
 	GRN_TEXT_INIT(&pathBuffer, 0);
-------------- next part --------------
HTML����������������������������...
Download 



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