Procházet zdrojové kódy

Improve memory accounting

Caleb James DeLisle před 9 roky
rodič
revize
7295960c39

+ 2 - 1
dht/Pathfinder.c

@@ -439,13 +439,14 @@ static void sendEvent(struct Pathfinder_pvt* pf, enum PFChan_Pathfinder ev, void
     Allocator_free(alloc);
 }
 
-struct Pathfinder* Pathfinder_register(struct Allocator* alloc,
+struct Pathfinder* Pathfinder_register(struct Allocator* allocator,
                                        struct Log* log,
                                        struct EventBase* base,
                                        struct Random* rand,
                                        struct Admin* admin,
                                        struct EventEmitter* ee)
 {
+    struct Allocator* alloc = Allocator_child(allocator);
     struct Pathfinder_pvt* pf = Allocator_calloc(alloc, sizeof(struct Pathfinder_pvt), 1);
     pf->alloc = alloc;
     pf->log = log;

+ 2 - 1
net/ControlHandler.c

@@ -195,11 +195,12 @@ static Iface_DEFUN incomingFromSwitchPinger(struct Message* msg, struct Iface* s
     return Iface_next(&ch->pub.coreIf, msg);
 }
 
-struct ControlHandler* ControlHandler_new(struct Allocator* alloc,
+struct ControlHandler* ControlHandler_new(struct Allocator* allocator,
                                           struct Log* logger,
                                           struct EventEmitter* ee,
                                           uint8_t myPublicKey[32])
 {
+    struct Allocator* alloc = Allocator_child(allocator);
     struct ControlHandler_pvt* ch = Allocator_calloc(alloc, sizeof(struct ControlHandler_pvt), 1);
     ch->alloc = alloc;
     ch->log = logger;

+ 2 - 1
net/ConverterV15.c

@@ -214,11 +214,12 @@ static Iface_DEFUN incomingFromSessionManagerIf(struct Message* msg, struct Ifac
     return Iface_next(&conv->pub.upperDistributorIf, msg);
 }
 
-struct ConverterV15* ConverterV15_new(struct Allocator* alloc,
+struct ConverterV15* ConverterV15_new(struct Allocator* allocator,
                                       struct Log* log,
                                       struct SessionManager* sm,
                                       uint8_t myIp6[16])
 {
+    struct Allocator* alloc = Allocator_child(allocator);
     struct ConverterV15_pvt* out = Allocator_calloc(alloc, sizeof(struct ConverterV15_pvt), 1);
     out->pub.upperDistributorIf.send = incomingFromUpperDistributorIf;
     out->pub.sessionManagerIf.send = incomingFromSessionManagerIf;

+ 4 - 1
net/EventEmitter.c

@@ -343,8 +343,11 @@ void EventEmitter_regPathfinderIface(struct EventEmitter* emitter, struct Iface*
     pf->pathfinderId = ArrayList_Pathfinders_put(ee->pathfinders, i, pf);
 }
 
-struct EventEmitter* EventEmitter_new(struct Allocator* alloc, struct Log* log, uint8_t* publicKey)
+struct EventEmitter* EventEmitter_new(struct Allocator* allocator,
+                                      struct Log* log,
+                                      uint8_t* publicKey)
 {
+    struct Allocator* alloc = Allocator_child(allocator);
     struct EventEmitter_pvt* ee = Allocator_calloc(alloc, sizeof(struct EventEmitter_pvt), 1);
     ee->log = log;
     ee->alloc = alloc;

+ 6 - 5
net/InterfaceController.c

@@ -968,10 +968,11 @@ struct InterfaceController* InterfaceController_new(struct CryptoAuth* ca,
                                                     struct Allocator* allocator,
                                                     struct EventEmitter* ee)
 {
+    struct Allocator* alloc = Allocator_child(allocator);
     struct InterfaceController_pvt* out =
-        Allocator_malloc(allocator, sizeof(struct InterfaceController_pvt));
+        Allocator_malloc(alloc, sizeof(struct InterfaceController_pvt));
     Bits_memcpyConst(out, (&(struct InterfaceController_pvt) {
-        .alloc = allocator,
+        .alloc = alloc,
         .ca = ca,
         .rand = rand,
         .switchCore = switchCore,
@@ -989,13 +990,13 @@ struct InterfaceController* InterfaceController_new(struct CryptoAuth* ca,
                                   out,
                                   PING_INTERVAL_MILLISECONDS,
                                   eventBase,
-                                  allocator)
+                                  alloc)
             : NULL
 
     }), sizeof(struct InterfaceController_pvt));
     Identity_set(out);
 
-    out->icis = ArrayList_OfIfaces_new(allocator);
+    out->icis = ArrayList_OfIfaces_new(alloc);
 
     out->eventEmitterIf.send = incomingFromEventEmitterIf;
     EventEmitter_regCore(ee, &out->eventEmitterIf, PFChan_Pathfinder_PEERS);
@@ -1010,7 +1011,7 @@ struct InterfaceController* InterfaceController_new(struct CryptoAuth* ca,
     Bits_memcpyConst(out->beacon.publicKey, ca->publicKey, 32);
     out->beacon.version_be = Endian_hostToBigEndian32(Version_CURRENT_PROTOCOL);
 
-    Timeout_setTimeout(beaconInterval, out, BEACON_INTERVAL, eventBase, allocator);
+    Timeout_setTimeout(beaconInterval, out, BEACON_INTERVAL, eventBase, alloc);
 
     return &out->pub;
 }

+ 2 - 1
net/InterfaceController_admin.c

@@ -177,8 +177,9 @@ static resetSession(Dict* args, void* vcontext, String* txid, struct Allocator*
 
 void InterfaceController_admin_register(struct InterfaceController* ic,
                                         struct Admin* admin,
-                                        struct Allocator* alloc)
+                                        struct Allocator* allocator)
 {
+    struct Allocator* alloc = Allocator_child(allocator);
     struct Context* ctx = Allocator_clone(alloc, (&(struct Context) {
         .alloc = alloc,
         .ic = ic,

+ 2 - 1
net/NetCore.c

@@ -32,11 +32,12 @@
 #include "net/TUNAdapter.h"
 
 struct NetCore* NetCore_new(uint8_t* privateKey,
-                            struct Allocator* alloc,
+                            struct Allocator* allocator,
                             struct EventBase* base,
                             struct Random* rand,
                             struct Log* log)
 {
+    struct Allocator* alloc = Allocator_child(allocator);
     struct NetCore* nc = Allocator_calloc(alloc, sizeof(struct NetCore), 1);
     nc->alloc = alloc;
     nc->base = base;

+ 2 - 1
net/PeerLink.c

@@ -66,8 +66,9 @@ void PeerLink_kbps(struct PeerLink* peerLink, struct PeerLink_Kbps* output)
     output->sendKbps = Kbps_accumulate(&pl->sendBw, now, Kbps_accumulate_NO_PACKET);
 }
 
-struct PeerLink* PeerLink_new(struct EventBase* base, struct Allocator* alloc)
+struct PeerLink* PeerLink_new(struct EventBase* base, struct Allocator* allocator)
 {
+    struct Allocator* alloc = Allocator_child(allocator);
     struct PeerLink_pvt* pl = Allocator_calloc(alloc, sizeof(struct PeerLink_pvt), 1);
     Identity_set(pl);
     pl->base = base;

+ 2 - 1
net/SessionManager.c

@@ -557,13 +557,14 @@ static Iface_DEFUN incomingFromEventIf(struct Message* msg, struct Iface* iface)
     return NULL;
 }
 
-struct SessionManager* SessionManager_new(struct Allocator* alloc,
+struct SessionManager* SessionManager_new(struct Allocator* allocator,
                                           struct EventBase* eventBase,
                                           struct CryptoAuth* cryptoAuth,
                                           struct Random* rand,
                                           struct Log* log,
                                           struct EventEmitter* ee)
 {
+    struct Allocator* alloc = Allocator_child(allocator);
     struct SessionManager_pvt* sm = Allocator_calloc(alloc, sizeof(struct SessionManager_pvt), 1);
     sm->alloc = alloc;
     sm->pub.switchIf.send = incomingFromSwitchIf;

+ 2 - 1
net/SwitchAdapter.c

@@ -69,8 +69,9 @@ static Iface_DEFUN incomingFromSwitchIf(struct Message* msg, struct Iface* switc
     return Iface_next(&sa->pub.sessionManagerIf, msg);
 }
 
-struct SwitchAdapter* SwitchAdapter_new(struct Allocator* alloc, struct Log* log)
+struct SwitchAdapter* SwitchAdapter_new(struct Allocator* allocator, struct Log* log)
 {
+    struct Allocator* alloc = Allocator_child(allocator);
     struct SwitchAdapter_pvt* out = Allocator_calloc(alloc, sizeof(struct SwitchAdapter_pvt), 1);
     out->pub.controlIf.send = incomingFromControlIf;
     out->pub.sessionManagerIf.send = incomingFromSessionManagerIf;

+ 2 - 1
net/SwitchPinger.c

@@ -350,8 +350,9 @@ struct SwitchPinger* SwitchPinger_new(struct EventBase* eventBase,
                                       struct Random* rand,
                                       struct Log* logger,
                                       struct Address* myAddr,
-                                      struct Allocator* alloc)
+                                      struct Allocator* allocator)
 {
+    struct Allocator* alloc = Allocator_child(allocator);
     struct SwitchPinger_pvt* sp = Allocator_malloc(alloc, sizeof(struct SwitchPinger_pvt));
     Bits_memcpyConst(sp, (&(struct SwitchPinger_pvt) {
         .pub = {

+ 2 - 1
net/SwitchPinger_admin.c

@@ -106,8 +106,9 @@ static void adminPing(Dict* args, void* vcontext, String* txid, struct Allocator
 
 void SwitchPinger_admin_register(struct SwitchPinger* sp,
                                  struct Admin* admin,
-                                 struct Allocator* alloc)
+                                 struct Allocator* allocator)
 {
+    struct Allocator* alloc = Allocator_child(allocator);
     struct Context* ctx = Allocator_clone(alloc, (&(struct Context) {
         .switchPinger = sp,
         .alloc = alloc,

+ 2 - 1
net/TUNAdapter.c

@@ -154,8 +154,9 @@ static Iface_DEFUN incomingFromUpperDistributorIf(struct Message* msg,
     return sendToTunIf(msg, ud);
 }
 
-struct TUNAdapter* TUNAdapter_new(struct Allocator* alloc, struct Log* log, uint8_t myIp6[16])
+struct TUNAdapter* TUNAdapter_new(struct Allocator* allocator, struct Log* log, uint8_t myIp6[16])
 {
+    struct Allocator* alloc = Allocator_child(allocator);
     struct TUNAdapter_pvt* out = Allocator_calloc(alloc, sizeof(struct TUNAdapter_pvt), 1);
     out->pub.tunIf.send = incomingFromTunIf;
     out->pub.ipTunnelIf.send = incomingFromIpTunnelIf;

+ 2 - 1
net/UpperDistributor.c

@@ -75,10 +75,11 @@ static Iface_DEFUN incomingFromSessionManagerIf(struct Message* msg, struct Ifac
     return NULL;
 }
 
-struct UpperDistributor* UpperDistributor_new(struct Allocator* alloc,
+struct UpperDistributor* UpperDistributor_new(struct Allocator* allocator,
                                               struct Log* log,
                                               struct EventEmitter* ee)
 {
+    struct Allocator* alloc = Allocator_child(allocator);
     struct UpperDistributor_pvt* out =
         Allocator_calloc(alloc, sizeof(struct UpperDistributor_pvt), 1);
     out->eventIf.send = incomingFromEventIf;