Browse Source

Test

etomic
jl777 7 years ago
parent
commit
c75d664171
  1. 25
      iguana/exchanges/LP_nativeDEX.c

25
iguana/exchanges/LP_nativeDEX.c

@ -1197,41 +1197,33 @@ struct LP_memory_list
{ {
struct LP_memory_list *next,*prev; struct LP_memory_list *next,*prev;
uint32_t timestamp,len; uint32_t timestamp,len;
void *ptr;
} *LP_memory_list; } *LP_memory_list;
void *LP_alloc(uint64_t len) void *LP_alloc(uint64_t len)
{ {
struct LP_memory_list *mp; struct LP_memory_list *mp;
mp = calloc(1,sizeof(*mp) + len); mp = calloc(1,sizeof(*mp));
printf("\n>>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu\n",mp,&mp[1],(long long)len); printf("\n>>>>>>>>>>> LP_alloc mp.%p ptr.%p len.%llu\n",mp,&mp[1],(long long)len);
mp->timestamp = (uint32_t)time(NULL); mp->timestamp = (uint32_t)time(NULL);
mp->len = (uint32_t)len; mp->len = (uint32_t)len;
mp->ptr = calloc(1,len);
portable_mutex_lock(&LP_cJSONmutex); portable_mutex_lock(&LP_cJSONmutex);
DL_APPEND(LP_memory_list,mp); DL_APPEND(LP_memory_list,mp);
portable_mutex_unlock(&LP_cJSONmutex); portable_mutex_unlock(&LP_cJSONmutex);
return(&mp[1]); return(mp->ptr);
} }
void *LP_realloc(void *ptr,uint64_t len) void *LP_realloc(void *ptr,uint64_t len)
{ {
struct LP_memory_list *mp = ptr; return(realloc(ptr,len));
if ( mp != 0 )
{
--mp;
printf("\n>>>>>>>>>>> LP_realloc mp.%p ptr.%p len.%llu\n",mp,&mp[1],(long long)len);
mp = realloc(mp,len + sizeof(*mp));
mp->timestamp = (uint32_t)time(NULL);
mp->len = (uint32_t)len;
return(&mp[1]);
} else return(LP_alloc(len));
} }
void LP_free(void *ptr) void LP_free(void *ptr)
{ {
static uint32_t lasttime; static uint32_t lasttime;
uint32_t now; int32_t n; uint64_t total = 0; struct LP_memory_list *mp,*tmp,*freemp = ptr; uint32_t now; int32_t n; uint64_t total = 0; struct LP_memory_list *mp,*tmp;
--freemp; printf("\n>>>>>>>>>>> LP_free ptr.%p\n",ptr);
printf("\n>>>>>>>>>>> LP_free freemp.%p\n",freemp);
if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) if ( (now= (uint32_t)time(NULL)) > lasttime+6 )
{ {
n = 0; n = 0;
@ -1245,7 +1237,7 @@ void LP_free(void *ptr)
} }
DL_FOREACH_SAFE(LP_memory_list,mp,tmp) DL_FOREACH_SAFE(LP_memory_list,mp,tmp)
{ {
if ( mp == freemp ) if ( mp->ptr == ptr )
break; break;
mp = 0; mp = 0;
} }
@ -1254,6 +1246,7 @@ void LP_free(void *ptr)
portable_mutex_lock(&LP_cJSONmutex); portable_mutex_lock(&LP_cJSONmutex);
DL_DELETE(LP_memory_list,mp); DL_DELETE(LP_memory_list,mp);
portable_mutex_unlock(&LP_cJSONmutex); portable_mutex_unlock(&LP_cJSONmutex);
free(mp->ptr);
free(mp); free(mp);
} // free from source file with #define redirect for alloc that wasnt } // free from source file with #define redirect for alloc that wasnt
} }

Loading…
Cancel
Save