aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-10-04 16:50:09 +1100
committerAldo Cortesi <aldo@nullcube.com>2016-10-04 16:52:58 +1100
commite18965268075bb440afb42afff7c2246bc6c7e3b (patch)
treeb58a1e9d2a572271a02b28b2f5e86ff0754a04f1
parent882c363ec57792b00ebf1f731ec5c5e4bd24d58d (diff)
downloadmitmproxy-e18965268075bb440afb42afff7c2246bc6c7e3b.tar.gz
mitmproxy-e18965268075bb440afb42afff7c2246bc6c7e3b.tar.bz2
mitmproxy-e18965268075bb440afb42afff7c2246bc6c7e3b.zip
mitmdump: use a dummy state object
Most of the mitmdump memory leak turns out to be due to our leaky handling of the state object. Since mitmdump doesn't actually use the state object, we can replace it with a shell.
-rw-r--r--mitmproxy/dump.py9
-rw-r--r--mitmproxy/flow/__init__.py4
-rw-r--r--mitmproxy/flow/state.py10
3 files changed, 13 insertions, 10 deletions
diff --git a/mitmproxy/dump.py b/mitmproxy/dump.py
index 0e942eac..92dce37b 100644
--- a/mitmproxy/dump.py
+++ b/mitmproxy/dump.py
@@ -35,7 +35,7 @@ class Options(options.Options):
class DumpMaster(flow.FlowMaster):
def __init__(self, server, options):
- flow.FlowMaster.__init__(self, options, server, flow.State())
+ flow.FlowMaster.__init__(self, options, server, flow.DummyState())
self.has_errored = False
self.addons.add(*builtins.default_addons())
self.addons.add(dumper.Dumper())
@@ -82,13 +82,6 @@ class DumpMaster(flow.FlowMaster):
if e.level == "error":
self.has_errored = True
- @controller.handler
- def request(self, f):
- f = super(DumpMaster, self).request(f)
- if f:
- self.state.delete_flow(f)
- return f
-
def run(self): # pragma: no cover
if self.options.rfile and not self.options.keepserving:
self.addons.done()
diff --git a/mitmproxy/flow/__init__.py b/mitmproxy/flow/__init__.py
index cb79482c..c857352c 100644
--- a/mitmproxy/flow/__init__.py
+++ b/mitmproxy/flow/__init__.py
@@ -6,10 +6,10 @@ from mitmproxy.flow.master import FlowMaster
from mitmproxy.flow.modules import (
AppRegistry, StreamLargeBodies
)
-from mitmproxy.flow.state import State, FlowView
+from mitmproxy.flow.state import State, DummyState, FlowView
__all__ = [
"export", "modules",
"FlowWriter", "FilteredFlowWriter", "FlowReader", "read_flows_from_paths",
- "FlowMaster", "AppRegistry", "StreamLargeBodies", "State", "FlowView",
+ "FlowMaster", "AppRegistry", "StreamLargeBodies", "DummyState", "State", "FlowView",
]
diff --git a/mitmproxy/flow/state.py b/mitmproxy/flow/state.py
index 759e53e4..4427f0bb 100644
--- a/mitmproxy/flow/state.py
+++ b/mitmproxy/flow/state.py
@@ -267,3 +267,13 @@ class State(object):
def killall(self, master):
self.flows.kill_all(master)
+
+
+class DummyState:
+ flows = ()
+
+ def add_flow(self, *args, **kwargs):
+ pass
+
+ def update_flow(self, *args, **kwargs):
+ pass