blob: 1346b5c5b56214dfc252e6315edd795fe7a9ee66 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
--- a/src/rpc/command_scheduler.cc
+++ b/src/rpc/command_scheduler.cc
@@ -63,15 +63,18 @@ CommandScheduler::insert(const std::stri
if (key.empty())
throw torrent::input_error("Scheduler received an empty key.");
- iterator itr = find(key);
-
- if (itr == end())
- itr = base_type::insert(end(), NULL);
- else
- delete *itr;
+ CommandSchedulerItem* current = new CommandSchedulerItem(key);
+ current->slot() = std::bind(&CommandScheduler::call_item, this, current);
- *itr = new CommandSchedulerItem(key);
- (*itr)->slot() = std::bind(&CommandScheduler::call_item, this, *itr);
+ iterator itr = find(key);
+ if (itr == end()) {
+ itr = base_type::insert(end(), current);
+ } else {
+ // swap in fully initialized command, and THEN delete the replaced one
+ CommandSchedulerItem* old = *itr;
+ *itr = current;
+ delete old;
+ }
return itr;
}
|