Skip to content

Commit 26b43c8

Browse files
addaleaxMylesBorins
authored andcommitted
src: add method to compute storage in WriteWrap
`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>
1 parent 319beaf commit 26b43c8

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/node_http2_core-inl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ inline void Nghttp2Session::SendPendingData() {
501501
while ((srcLength = nghttp2_session_mem_send(session_, &src)) > 0) {
502502
if (req == nullptr) {
503503
req = AllocateSend();
504-
destRemaining = req->self_size();
504+
destRemaining = req->ExtraSize();
505505
dest = req->Extra();
506506
}
507507
DEBUG_HTTP2("Nghttp2Session %s: nghttp2 has %d bytes to send\n",
@@ -523,7 +523,7 @@ inline void Nghttp2Session::SendPendingData() {
523523
srcRemaining -= destRemaining;
524524
srcOffset += destRemaining;
525525
req = AllocateSend();
526-
destRemaining = req->self_size();
526+
destRemaining = req->ExtraSize();
527527
dest = req->Extra();
528528
}
529529

src/stream_base-inl.h

+4
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ char* WriteWrap::Extra(size_t offset) {
167167
offset;
168168
}
169169

170+
size_t WriteWrap::ExtraSize() const {
171+
return storage_size_ - ROUND_UP(sizeof(*this), kAlignSize);
172+
}
173+
170174
} // namespace node
171175

172176
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

src/stream_base.h

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class WriteWrap: public ReqWrap<uv_write_t>,
7777
size_t extra = 0);
7878
inline void Dispose();
7979
inline char* Extra(size_t offset = 0);
80+
inline size_t ExtraSize() const;
8081

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

0 commit comments

Comments
 (0)