Skip to content

Commit ad5f2d2

Browse files
fhinkelgibfahn
authored andcommitted
src: use unique_ptr for http2_state
PR-URL: #17078 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 7b9458b commit ad5f2d2

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/env-inl.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ inline Environment::~Environment() {
361361
delete[] heap_statistics_buffer_;
362362
delete[] heap_space_statistics_buffer_;
363363
delete[] http_parser_buffer_;
364-
delete http2_state_;
365364
free(performance_state_);
366365
}
367366

@@ -516,12 +515,13 @@ inline void Environment::set_http_parser_buffer(char* buffer) {
516515
}
517516

518517
inline http2::http2_state* Environment::http2_state() const {
519-
return http2_state_;
518+
return http2_state_.get();
520519
}
521520

522-
inline void Environment::set_http2_state(http2::http2_state* buffer) {
523-
CHECK_EQ(http2_state_, nullptr); // Should be set only once.
524-
http2_state_ = buffer;
521+
inline void Environment::set_http2_state(
522+
std::unique_ptr<http2::http2_state> buffer) {
523+
CHECK(!http2_state_); // Should be set only once.
524+
http2_state_ = std::move(buffer);
525525
}
526526

527527
inline double* Environment::fs_stats_field_array() const {

src/env.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ class Environment {
613613
inline void set_http_parser_buffer(char* buffer);
614614

615615
inline http2::http2_state* http2_state() const;
616-
inline void set_http2_state(http2::http2_state * state);
616+
inline void set_http2_state(std::unique_ptr<http2::http2_state> state);
617617

618618
inline double* fs_stats_field_array() const;
619619
inline void set_fs_stats_field_array(double* fields);
@@ -731,7 +731,7 @@ class Environment {
731731
double* heap_space_statistics_buffer_ = nullptr;
732732

733733
char* http_parser_buffer_;
734-
http2::http2_state* http2_state_ = nullptr;
734+
std::unique_ptr<http2::http2_state> http2_state_;
735735

736736
double* fs_stats_field_array_;
737737

src/node_http2.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -2069,8 +2069,7 @@ void Initialize(Local<Object> target,
20692069
Isolate* isolate = env->isolate();
20702070
HandleScope scope(isolate);
20712071

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

20752074
#define SET_STATE_TYPEDARRAY(name, field) \
20762075
target->Set(context, \
@@ -2092,6 +2091,8 @@ void Initialize(Local<Object> target,
20922091
"optionsBuffer", state->options_buffer.GetJSArray());
20932092
#undef SET_STATE_TYPEDARRAY
20942093

2094+
env->set_http2_state(std::move(state));
2095+
20952096
NODE_DEFINE_CONSTANT(target, PADDING_BUF_FRAME_LENGTH);
20962097
NODE_DEFINE_CONSTANT(target, PADDING_BUF_MAX_PAYLOAD_LENGTH);
20972098
NODE_DEFINE_CONSTANT(target, PADDING_BUF_RETURN_VALUE);

0 commit comments

Comments
 (0)