don't delete last scripted assignment before it is sent out

This commit is contained in:
Stephen Birarda 2013-10-31 10:10:49 -07:00
parent e0e13fe2ed
commit 21fe7e6fe0

View file

@ -457,14 +457,13 @@ Assignment* DomainServer::deployableAssignmentForRequest(Assignment& requestAssi
Assignment* deployableAssignment = *assignment;
if ((*assignment)->getType() == Assignment::AgentType) {
// if this is a script assignment we need to delete it to avoid a memory leak
// or if there is more than one instance to send out, simpy decrease the number of instances
if ((*assignment)->getNumberOfInstances() > 1) {
(*assignment)->decrementNumberOfInstances();
} else {
// if there is more than one instance to send out, simply decrease the number of instances
if ((*assignment)->getNumberOfInstances() == 1) {
_assignmentQueue.erase(assignment);
delete *assignment;
}
(*assignment)->decrementNumberOfInstances();
} else {
// remove the assignment from the queue
_assignmentQueue.erase(assignment);
@ -735,6 +734,11 @@ int DomainServer::run() {
nodeList->getNodeSocket()->send((sockaddr*) &senderAddress,
broadcastPacket,
numHeaderBytes + numAssignmentBytes);
if (assignmentToDeploy->getNumberOfInstances() == 0) {
// there are no more instances of this script to send out, delete it
delete assignmentToDeploy;
}
}
}