Skip to content

Commit

Permalink
src: use unique_ptr for http2_state
Browse files Browse the repository at this point in the history
PR-URL: #17078
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
fhinkel authored and MylesBorins committed Dec 11, 2017
1 parent e900090 commit 60423f5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}

Expand Down Expand Up @@ -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<http2::http2_state> buffer) {
CHECK(!http2_state_); // Should be set only once.
http2_state_ = std::move(buffer);
}

inline double* Environment::fs_stats_field_array() const {
Expand Down
4 changes: 2 additions & 2 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,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<http2::http2_state> state);

inline double* fs_stats_field_array() const;
inline void set_fs_stats_field_array(double* fields);
Expand Down Expand Up @@ -737,7 +737,7 @@ class Environment {
double* heap_space_statistics_buffer_ = nullptr;

char* http_parser_buffer_;
http2::http2_state* http2_state_ = nullptr;
std::unique_ptr<http2::http2_state> http2_state_;

double* fs_stats_field_array_;

Expand Down
5 changes: 3 additions & 2 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2069,8 +2069,7 @@ void Initialize(Local<Object> target,
Isolate* isolate = env->isolate();
HandleScope scope(isolate);

http2_state* state = new http2_state(isolate);
env->set_http2_state(state);
std::unique_ptr<http2_state> state(new http2_state(isolate));

#define SET_STATE_TYPEDARRAY(name, field) \
target->Set(context, \
Expand All @@ -2092,6 +2091,8 @@ void Initialize(Local<Object> 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);
Expand Down

0 comments on commit 60423f5

Please sign in to comment.