Skip to content

Commit

Permalink
src: add method to compute storage in WriteWrap
Browse files Browse the repository at this point in the history
`WriteWrap` instances may contain extra storage space.
`self_size()` returns the size of the *entire* struct, member fields as
well as storage space, so it is not an accurate measure for the
storage space available.

Add a method `ExtraSize()` (like the existing `Extra()` for accessing
the storage memory) that yields the wanted value, and use it
in the HTTP2 impl to fix a crash.

PR-URL: #16727
Refs: #16669
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax authored and MylesBorins committed Dec 7, 2017
1 parent 7e663d3 commit 8ffb24b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/node_http2_core-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ inline void Nghttp2Session::SendPendingData() {
while ((srcLength = nghttp2_session_mem_send(session_, &src)) > 0) {
if (req == nullptr) {
req = AllocateSend();
destRemaining = req->self_size();
destRemaining = req->ExtraSize();
dest = req->Extra();
}
DEBUG_HTTP2("Nghttp2Session %s: nghttp2 has %d bytes to send\n",
Expand All @@ -523,7 +523,7 @@ inline void Nghttp2Session::SendPendingData() {
srcRemaining -= destRemaining;
srcOffset += destRemaining;
req = AllocateSend();
destRemaining = req->self_size();
destRemaining = req->ExtraSize();
dest = req->Extra();
}

Expand Down
4 changes: 4 additions & 0 deletions src/stream_base-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ char* WriteWrap::Extra(size_t offset) {
offset;
}

size_t WriteWrap::ExtraSize() const {
return storage_size_ - ROUND_UP(sizeof(*this), kAlignSize);
}

} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down
1 change: 1 addition & 0 deletions src/stream_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class WriteWrap: public ReqWrap<uv_write_t>,
size_t extra = 0);
inline void Dispose();
inline char* Extra(size_t offset = 0);
inline size_t ExtraSize() const;

inline StreamBase* wrap() const { return wrap_; }

Expand Down

0 comments on commit 8ffb24b

Please sign in to comment.