فهرست منبع

fix some malloc(0)

ambrop7 13 سال پیش
والد
کامیت
7e5044f090
2فایلهای تغییر یافته به همراه9 افزوده شده و 7 حذف شده
  1. 4 3
      ncd/NCDInterpValue.c
  2. 5 4
      ncd/modules/value.c

+ 4 - 3
ncd/NCDInterpValue.c

@@ -32,6 +32,7 @@
 
 #include <misc/offset.h>
 #include <misc/split_string.h>
+#include <misc/balloc.h>
 #include <base/BLog.h>
 
 #include "NCDInterpValue.h"
@@ -121,7 +122,7 @@ void NCDInterpValue_Free (NCDInterpValue *o)
 {
     switch (o->type) {
         case NCDVALUE_STRING: {
-            free(o->string);
+            BFree(o->string);
         } break;
         
         case NCDVALUE_VAR: {
@@ -155,8 +156,8 @@ int NCDInterpValue_InitString (NCDInterpValue *o, const char *string, size_t len
 {
     o->type = NCDVALUE_STRING;
     
-    if (!(o->string = malloc(len))) {
-        BLog(BLOG_ERROR, "malloc failed");
+    if (!(o->string = BAlloc(len))) {
+        BLog(BLOG_ERROR, "BAlloc failed");
         return 0;
     }
     memcpy(o->string, string, len);

+ 5 - 4
ncd/modules/value.c

@@ -120,6 +120,7 @@
 #include <misc/offset.h>
 #include <misc/debug.h>
 #include <misc/parse_number.h>
+#include <misc/balloc.h>
 #include <structure/LinkedList0.h>
 #include <structure/IndexedList.h>
 #include <structure/BCountAVL.h>
@@ -231,7 +232,7 @@ static void value_cleanup (struct value *v)
     
     switch (v->type) {
         case NCDVAL_STRING: {
-            free(v->string.string);
+            BFree(v->string.string);
         } break;
         
         case NCDVAL_LIST: {
@@ -279,7 +280,7 @@ static void value_delete (struct value *v)
     
     switch (v->type) {
         case NCDVAL_STRING: {
-            free(v->string.string);
+            BFree(v->string.string);
         } break;
         
         case NCDVAL_LIST: {
@@ -314,8 +315,8 @@ static struct value * value_init_string (NCDModuleInst *i, const uint8_t *str, s
     v->parent = NULL;
     v->type = NCDVAL_STRING;
     
-    if (!(v->string.string = malloc(len))) {
-        ModuleLog(i, BLOG_ERROR, "malloc failed");
+    if (!(v->string.string = BAlloc(len))) {
+        ModuleLog(i, BLOG_ERROR, "BAlloc failed");
         goto fail1;
     }