-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C-API] Http transport doesn't correctly preserve the request body #5890
Comments
cc @michael-wb - I've been chasing this for a while in dart and this is the best explanation I could come up with. My understanding of C++ is rather superficial though, so there may be something else at play. |
@nirinchev - I am reworking this area due to requests from @RedBeard0531, so I will look into this issue as part of that. |
@nirinchev's analysis is correct. You need to either copy the request into the CompletionData, or create the CompletionData first, and have the c request refer into its |
➤ Michael Wilkerson-Barker commented: Updated send_request_to_server has been fixed in PR 5898 |
➤ Michael Wilkerson-Barker commented: Updated mechanism for the http C_API and added a test to verify operation |
When strings are small, they will be allocated on the stack rather than the heap, which means that a pointer to their
.data()
will become invalid when the string is moved. This seems to be what's happening after #5743 started preserving the request in the completion callback.realm-core/src/realm/object-store/c_api/http.cpp
Lines 74 to 81 in 52b297a
Here, we construct a
realm_http_request_t
where the body points torequest.body.data()
but then westd::move
the request to constructcompletion_data
. When the request body is small, e.g.{ "name": "a" }
, the string will be copied and the old data will now be garbage. I imagine the same issue may affect the url, but it seems our urls are long enough for it not to be a problem.The text was updated successfully, but these errors were encountered: