[Groonga-commit] groonga/groonga [master] Copy data to ngx_buf_t before finishing to use context

Back to archive index

null+****@clear***** null+****@clear*****
2012年 6月 4日 (月) 16:33:45 JST


Ryo Onodera	2012-06-04 16:33:45 +0900 (Mon, 04 Jun 2012)

  New Revision: 35df885ef9c140c37669a9ffccbe38a81688d9c0

  Log:
    Copy data to ngx_buf_t before finishing to use context

  Modified files:
    src/nginx-module/ngx_http_groonga_module.c

  Modified: src/nginx-module/ngx_http_groonga_module.c (+9 -2)
===================================================================
--- src/nginx-module/ngx_http_groonga_module.c    2012-06-04 16:08:47 +0900 (d877159)
+++ src/nginx-module/ngx_http_groonga_module.c    2012-06-04 16:33:45 +0900 (49c0a5d)
@@ -100,6 +100,7 @@ ngx_http_groonga_handler(ngx_http_request_t *r)
   int flags = 0;
   char *result = NULL;
   unsigned int result_size = 0;
+  unsigned char *body_data;
 
   ngx_http_groonga_loc_conf_t *loc_conf;
   loc_conf = ngx_http_get_module_loc_conf(r, ngx_http_groonga_module);
@@ -130,6 +131,12 @@ ngx_http_groonga_handler(ngx_http_request_t *r)
     return rc;
   }
 
+  body_data = ngx_pcalloc(r->pool, result_size);
+  if (body_data == NULL) {
+    return NGX_HTTP_INTERNAL_SERVER_ERROR;
+  }
+  ngx_memcpy(body_data, result, result_size);
+
   grn_ctx_fin(context);
   rc = ngx_http_groonga_context_check(context);
   if (rc != NGX_OK) {
@@ -164,8 +171,8 @@ ngx_http_groonga_handler(ngx_http_request_t *r)
   out.next = NULL;
 
   /* adjust the pointers of the buffer */
-  b->pos = (u_char *)result;
-  b->last = (u_char *)result + result_size;
+  b->pos = body_data;
+  b->last = body_data + result_size;
   b->memory = 1;    /* this buffer is in memory */
   b->last_buf = 1;  /* this is the last buffer in the buffer chain */
 




Groonga-commit メーリングリストの案内
Back to archive index