From a0bafc5b8dc419b15d34ec073ad9b7fb7a2d6f41 Mon Sep 17 00:00:00 2001 From: Franziska Hinkelmann Date: Thu, 16 Nov 2017 15:56:20 +0100 Subject: [PATCH] src: use unique_ptr for http2_state --- src/env-inl.h | 10 +++++----- src/env.h | 4 ++-- src/node_http2.cc | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/env-inl.h b/src/env-inl.h index 4dadf5ea2c1978..541bb676b63988 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -340,7 +340,6 @@ inline Environment::~Environment() { delete[] heap_statistics_buffer_; delete[] heap_space_statistics_buffer_; delete[] http_parser_buffer_; - delete http2_state_; free(performance_state_); } @@ -495,12 +494,13 @@ inline void Environment::set_http_parser_buffer(char* buffer) { } inline http2::http2_state* Environment::http2_state() const { - return http2_state_; + return http2_state_.get(); } -inline void Environment::set_http2_state(http2::http2_state* buffer) { - CHECK_EQ(http2_state_, nullptr); // Should be set only once. - http2_state_ = buffer; +inline void Environment::set_http2_state( + std::unique_ptr buffer) { + CHECK(!http2_state_); // Should be set only once. + http2_state_ = std::move(buffer); } inline double* Environment::fs_stats_field_array() const { diff --git a/src/env.h b/src/env.h index e37dcf17aeb1d6..735b5af424d062 100644 --- a/src/env.h +++ b/src/env.h @@ -616,7 +616,7 @@ class Environment { inline void set_http_parser_buffer(char* buffer); inline http2::http2_state* http2_state() const; - inline void set_http2_state(http2::http2_state * state); + inline void set_http2_state(std::unique_ptr state); inline double* fs_stats_field_array() const; inline void set_fs_stats_field_array(double* fields); @@ -747,7 +747,7 @@ class Environment { double* heap_space_statistics_buffer_ = nullptr; char* http_parser_buffer_; - http2::http2_state* http2_state_ = nullptr; + std::unique_ptr http2_state_; double* fs_stats_field_array_; diff --git a/src/node_http2.cc b/src/node_http2.cc index 84c1cfd97718fa..bdf0d31b4774a1 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -1211,8 +1211,7 @@ void Initialize(Local target, Isolate* isolate = env->isolate(); HandleScope scope(isolate); - http2_state* state = new http2_state(isolate); - env->set_http2_state(state); + std::unique_ptr state(new http2_state(isolate)); #define SET_STATE_TYPEDARRAY(name, field) \ target->Set(context, \ @@ -1234,6 +1233,8 @@ void Initialize(Local target, "optionsBuffer", state->options_buffer.GetJSArray()); #undef SET_STATE_TYPEDARRAY + env->set_http2_state(std::move(state)); + NODE_DEFINE_CONSTANT(target, PADDING_BUF_FRAME_LENGTH); NODE_DEFINE_CONSTANT(target, PADDING_BUF_MAX_PAYLOAD_LENGTH); NODE_DEFINE_CONSTANT(target, PADDING_BUF_RETURN_VALUE);