From 93283f2c2de4d36e6f95ba8d49c8eb0e4a317c13 Mon Sep 17 00:00:00 2001 From: jazeltq Date: Sat, 6 Sep 2014 10:43:09 +0800 Subject: [PATCH] fix memory leak for function _safe_log In _safe_log it uses recursive closure. The gc can not free stack for this recursive closure for cycle-reference. So cut down the cycle to fix it. Resolved-bug: #1365892 Change-Id: I05fbd7091b886344d76b172a5ad66d9225599d69 --- oslo/messaging/_drivers/common.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/oslo/messaging/_drivers/common.py b/oslo/messaging/_drivers/common.py index 71ca02b38..dca9809bc 100644 --- a/oslo/messaging/_drivers/common.py +++ b/oslo/messaging/_drivers/common.py @@ -69,6 +69,8 @@ _MESSAGE_KEY = 'oslo.message' _REMOTE_POSTFIX = '_Remote' +_SANITIZE = ['_context_auth_token', 'auth_token', 'new_pass'] + class RPCException(Exception): msg_fmt = _("An unknown RPC related exception occurred.") @@ -159,21 +161,21 @@ class Connection(object): raise NotImplementedError() +def _fix_passwords(d): + """Sanitizes the password fields in the dictionary.""" + for k in six.iterkeys(d): + if k.lower().find('password') != -1: + d[k] = '' + elif k.lower() in _SANITIZE: + d[k] = '' + elif isinstance(d[k], dict): + _fix_passwords(d[k]) + + return d + + def _safe_log(log_func, msg, msg_data): """Sanitizes the msg_data field before logging.""" - SANITIZE = ['_context_auth_token', 'auth_token', 'new_pass'] - - def _fix_passwords(d): - """Sanitizes the password fields in the dictionary.""" - for k in six.iterkeys(d): - if k.lower().find('password') != -1: - d[k] = '' - elif k.lower() in SANITIZE: - d[k] = '' - elif isinstance(d[k], dict): - _fix_passwords(d[k]) - return d - return log_func(msg, _fix_passwords(copy.deepcopy(msg_data)))