Skip to content

Commit 2d50b5e

Browse files
fhinkeladdaleax
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 d61cd9d commit 2d50b5e

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/env-inl.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ inline Environment::~Environment() {
341341
delete[] heap_statistics_buffer_;
342342
delete[] heap_space_statistics_buffer_;
343343
delete[] http_parser_buffer_;
344-
delete http2_state_;
345344
free(performance_state_);
346345
}
347346

@@ -496,12 +495,13 @@ inline void Environment::set_http_parser_buffer(char* buffer) {
496495
}
497496

498497
inline http2::http2_state* Environment::http2_state() const {
499-
return http2_state_;
498+
return http2_state_.get();
500499
}
501500

502-
inline void Environment::set_http2_state(http2::http2_state* buffer) {
503-
CHECK_EQ(http2_state_, nullptr); // Should be set only once.
504-
http2_state_ = buffer;
501+
inline void Environment::set_http2_state(
502+
std::unique_ptr<http2::http2_state> buffer) {
503+
CHECK(!http2_state_); // Should be set only once.
504+
http2_state_ = std::move(buffer);
505505
}
506506

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

src/env.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ class Environment {
617617
inline void set_http_parser_buffer(char* buffer);
618618

619619
inline http2::http2_state* http2_state() const;
620-
inline void set_http2_state(http2::http2_state * state);
620+
inline void set_http2_state(std::unique_ptr<http2::http2_state> state);
621621

622622
inline double* fs_stats_field_array() const;
623623
inline void set_fs_stats_field_array(double* fields);
@@ -752,7 +752,7 @@ class Environment {
752752
double* heap_space_statistics_buffer_ = nullptr;
753753

754754
char* http_parser_buffer_;
755-
http2::http2_state* http2_state_ = nullptr;
755+
std::unique_ptr<http2::http2_state> http2_state_;
756756

757757
double* fs_stats_field_array_;
758758

src/node_http2.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,8 +1211,7 @@ void Initialize(Local<Object> target,
12111211
Isolate* isolate = env->isolate();
12121212
HandleScope scope(isolate);
12131213

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

12171216
#define SET_STATE_TYPEDARRAY(name, field) \
12181217
target->Set(context, \
@@ -1234,6 +1233,8 @@ void Initialize(Local<Object> target,
12341233
"optionsBuffer", state->options_buffer.GetJSArray());
12351234
#undef SET_STATE_TYPEDARRAY
12361235

1236+
env->set_http2_state(std::move(state));
1237+
12371238
NODE_DEFINE_CONSTANT(target, PADDING_BUF_FRAME_LENGTH);
12381239
NODE_DEFINE_CONSTANT(target, PADDING_BUF_MAX_PAYLOAD_LENGTH);
12391240
NODE_DEFINE_CONSTANT(target, PADDING_BUF_RETURN_VALUE);

0 commit comments

Comments
 (0)