summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Murashkin <iam@google.com>2019-11-11 16:53:05 -0800
committerIgor Murashkin <iam@google.com>2019-11-11 16:53:05 -0800
commitf2bfb6033afc524d4bb48aaa8c957e223000ad6d (patch)
tree15ac6f89ad47dc0cbdcf740c91b0c0829d86c137
parent96616d3ccb430235fe81b84b197cedd499b73373 (diff)
downloadRxCpp-f2bfb6033afc524d4bb48aaa8c957e223000ad6d.tar.gz
observable: Fix dangling use in #as_blocking
Using rxcpp::subscriber by-reference in a lambda in the as_blocking operator would occasionally cause #on_error to crash in std::shared_ptr::get Bug: 143900063 Change-Id: Ie5b06b1c7872b08f256af569b408ea987d80fae7
-rw-r--r--Rx/v2/src/rxcpp/rx-observable.hpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/Rx/v2/src/rxcpp/rx-observable.hpp b/Rx/v2/src/rxcpp/rx-observable.hpp
index 4f42007..7e3d567 100644
--- a/Rx/v2/src/rxcpp/rx-observable.hpp
+++ b/Rx/v2/src/rxcpp/rx-observable.hpp
@@ -174,22 +174,26 @@ class blocking_observable
std::mutex lock;
std::condition_variable wake;
bool disposed = false;
- rxu::error_ptr error;
auto dest = make_subscriber<T>(std::forward<ArgN>(an)...);
+ rxu::error_ptr error;
+ bool has_error = false;
+
// keep any error to rethrow at the end.
+ // copy 'dest' by-value to avoid using it after it goes out of scope.
auto scbr = make_subscriber<T>(
dest,
- [&](T t){dest.on_next(t);},
- [&](rxu::error_ptr e){
+ [dest](T t){dest.on_next(t);},
+ [dest,&error,&has_error,do_rethrow](rxu::error_ptr e){
if (do_rethrow) {
+ has_error = true;
error = e;
} else {
dest.on_error(e);
}
},
- [&](){dest.on_completed();}
+ [dest](){dest.on_completed();}
);
auto cs = scbr.get_subscription();
@@ -208,7 +212,7 @@ class blocking_observable
return disposed;
});
- if (error) {rxu::rethrow_exception(error);}
+ if (has_error) {rxu::rethrow_exception(error);}
}
public: