Skip to content

Commit

Permalink
Should fix the memory leak, and hopefully the segmentation fault
Browse files Browse the repository at this point in the history
  • Loading branch information
Dadoum committed Aug 15, 2023
1 parent 3ef10ba commit 18df13c
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class AnisetteService {
GC.collect();
}

ADI adi = makeGarbageCollectedADI(libraryPath);
scope ADI adi = makeGarbageCollectedADI(libraryPath);
adi.provisioningPath = provisioningPath;
adi.identifier = identifier.toUpper()[0..16];

Expand Down Expand Up @@ -313,7 +313,6 @@ class AnisetteService {
];
log.infoF!"[>> %s] Timeout!"(requestUUID);
socket.send(timeoutJs.toString(JSONOptions.doNotEscapeSlashes));
socket.close();
return;
}

Expand All @@ -331,7 +330,6 @@ class AnisetteService {

log.infoF!"[>> %s] It is invalid: %s"(requestUUID, ex);
socket.send(response.toString(JSONOptions.doNotEscapeSlashes));
socket.close();
return;
}

Expand All @@ -342,7 +340,7 @@ class AnisetteService {
GC.enable();
GC.collect();
}
ADI adi = makeGarbageCollectedADI(libraryPath);
scope ADI adi = makeGarbageCollectedADI(libraryPath);
auto provisioningPath = file.getcwd()
.buildPath("provisioning")
.buildPath(identifier);
Expand All @@ -367,7 +365,6 @@ class AnisetteService {
];
log.infoF!"[>> %s] Timeout!"(requestUUID);
socket.send(timeoutJs.toString(JSONOptions.doNotEscapeSlashes));
socket.close();
return;
}

Expand All @@ -379,6 +376,7 @@ class AnisetteService {
log.infoF!"[<< %s] Received SPIM."(requestUUID);
auto cpimAndCo = adi.startProvisioning(-2, Base64.decode(spim));
session = cpimAndCo.session;
scope(failure) adi.destroyProvisioning(session);

response = [
"result": "GiveEndProvisioningData",
Expand All @@ -404,7 +402,6 @@ class AnisetteService {
];
log.infoF!"[>> %s] Timeout!"(requestUUID);
socket.send(timeoutJs.toString(JSONOptions.doNotEscapeSlashes));
socket.close();
return;
}

Expand Down Expand Up @@ -442,7 +439,7 @@ class AnisetteService {

private ADI makeGarbageCollectedADI(string libraryPath) {
extern(C) void* malloc_GC(size_t sz) {
return GC.malloc(sz, GC.BlkAttr.NO_MOVE);
return GC.malloc(sz, GC.BlkAttr.NO_MOVE | GC.BlkAttr.NO_SCAN);
}

extern(C) void free_GC(void* ptr) {
Expand Down

0 comments on commit 18df13c

Please sign in to comment.