Skip to content

Commit a87f846

Browse files
addaleaxcjihrig
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 <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 77e4ec8 commit a87f846

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
@@ -503,7 +503,7 @@ inline void Nghttp2Session::SendPendingData() {
503503
while ((srcLength = nghttp2_session_mem_send(session_, &src)) > 0) {
504504
if (req == nullptr) {
505505
req = AllocateSend();
506-
destRemaining = req->self_size();
506+
destRemaining = req->ExtraSize();
507507
dest = req->Extra();
508508
}
509509
DEBUG_HTTP2("Nghttp2Session %s: nghttp2 has %d bytes to send\n",
@@ -525,7 +525,7 @@ inline void Nghttp2Session::SendPendingData() {
525525
srcRemaining -= destRemaining;
526526
srcOffset += destRemaining;
527527
req = AllocateSend();
528-
destRemaining = req->self_size();
528+
destRemaining = req->ExtraSize();
529529
dest = req->Extra();
530530
}
531531

src/stream_base-inl.h

+4
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ char* WriteWrap::Extra(size_t offset) {
160160
offset;
161161
}
162162

163+
size_t WriteWrap::ExtraSize() const {
164+
return storage_size_ - ROUND_UP(sizeof(*this), kAlignSize);
165+
}
166+
163167
} // namespace node
164168

165169
#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)