diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index c79287421..3c8c376db 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -829,7 +829,7 @@ char *jstr(cJSON *json,char *field) { if ( json == 0 ) return(0); if ( field == char *jstri(cJSON *json,int32_t i) { return(cJSON_str(cJSON_GetArrayItem(json,i))); } char *jprint(cJSON *json,int32_t freeflag) { - char *str; + char *str,*retstr; /*static portable_mutex_t mutex; static int32_t initflag; if ( initflag == 0 ) { @@ -843,11 +843,11 @@ char *jprint(cJSON *json,int32_t freeflag) str = cJSON_Print(json), _stripwhite(str,' '); if ( freeflag != 0 ) free_json(json); - //retstr = LP_alloc(strlen(str) + 1); - //strcpy(retstr,str); - //cJSON_free(str); garbage collected + retstr = LP_alloc(strlen(str) + 1); + strcpy(retstr,str); + cJSON_free(str); //portable_mutex_unlock(&mutex); - return(str); + return(retstr); } bits256 get_API_bits256(cJSON *obj) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 1f71f2c01..d1cbba606 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1210,7 +1210,7 @@ void *LP_alloc(uint64_t len) //printf("\n>>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu\n",mp,mp->ptr,(long long)len); mp->timestamp = (uint32_t)time(NULL); mp->len = (uint32_t)len; - mp->ptr = &mp[1]; + mp->ptr = calloc(1,len); portable_mutex_lock(&LP_cJSONmutex); DL_APPEND(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); @@ -1225,8 +1225,7 @@ void *LP_realloc(void *ptr,uint64_t len) void LP_free(void *ptr) { static uint32_t lasttime,unknown; - uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp,*freemp = ptr; - --freemp; + uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { n = lagging = 0; @@ -1239,7 +1238,7 @@ void LP_free(void *ptr) { lagging++; DL_DELETE(LP_memory_list,mp); - //free(mp->ptr); + free(mp->ptr); free(mp); } } @@ -1253,15 +1252,13 @@ void LP_free(void *ptr) break; mp = 0; } - if ( mp != freemp ) - printf("mp %p != %p\n",mp,freemp); if ( mp != 0 ) { portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_memory_list,mp); portable_mutex_unlock(&LP_cJSONmutex); //printf(">>>>>>>>>>> LP_free ptr.%p mp.%p len.%u\n",ptr,mp,mp->len); - //free(mp->ptr); + free(mp->ptr); free(mp); } else unknown++; // free from source file with #define redirect for alloc that wasnt }