[Groonga-commit] groonga/groonga at 370c539 [master] Add an error check for malloc

Back to archive index

Susumu Yata null+****@clear*****
Mon Apr 11 00:51:08 JST 2016


Susumu Yata	2016-04-11 00:51:08 +0900 (Mon, 11 Apr 2016)

  New Revision: 370c539a55b1e0824d6bc086cfc71be979ae7bcc
  https://github.com/groonga/groonga/commit/370c539a55b1e0824d6bc086cfc71be979ae7bcc

  Message:
    Add an error check for malloc
    
    GitHub: #523

  Modified files:
    lib/ctx.c

  Modified: lib/ctx.c (+19 -17)
===================================================================
--- lib/ctx.c    2016-04-11 00:25:28 +0900 (39cba78)
+++ lib/ctx.c    2016-04-11 00:51:08 +0900 (8af8b1a)
@@ -367,24 +367,26 @@ grn_alloc_info_add(void *address, size_t size,
 
   CRITICAL_SECTION_ENTER(grn_alloc_info_lock);
   new_alloc_info = malloc(sizeof(grn_alloc_info));
-  new_alloc_info->address = address;
-  new_alloc_info->size = size;
-  new_alloc_info->freed = GRN_FALSE;
-  grn_alloc_info_set_backtrace(new_alloc_info->alloc_backtrace,
-                               sizeof(new_alloc_info->alloc_backtrace));
-  if (file) {
-    new_alloc_info->file = strdup(file);
-  } else {
-    new_alloc_info->file = NULL;
-  }
-  new_alloc_info->line = line;
-  if (func) {
-    new_alloc_info->func = strdup(func);
-  } else {
-    new_alloc_info->func = NULL;
+  if (new_alloc_info) {
+    new_alloc_info->address = address;
+    new_alloc_info->size = size;
+    new_alloc_info->freed = GRN_FALSE;
+    grn_alloc_info_set_backtrace(new_alloc_info->alloc_backtrace,
+                                 sizeof(new_alloc_info->alloc_backtrace));
+    if (file) {
+      new_alloc_info->file = strdup(file);
+    } else {
+      new_alloc_info->file = NULL;
+    }
+    new_alloc_info->line = line;
+    if (func) {
+      new_alloc_info->func = strdup(func);
+    } else {
+      new_alloc_info->func = NULL;
+    }
+    new_alloc_info->next = ctx->impl->alloc_info;
+    ctx->impl->alloc_info = new_alloc_info;
   }
-  new_alloc_info->next = ctx->impl->alloc_info;
-  ctx->impl->alloc_info = new_alloc_info;
   CRITICAL_SECTION_LEAVE(grn_alloc_info_lock);
 }
 
-------------- next part --------------
HTML����������������������������...
Télécharger 



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