-
Notifications
You must be signed in to change notification settings - Fork 956
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
Incorrect implementation of cpr::Session move constructor and move assignment operator #990
Comments
@Polarhigh thanks for reporting! I will try to take a look at this over the next few weeks. |
I decided to make As a solution I suggest using some kind of a container like Example: #include "cpr/session.h"
#include <iostream>
#include <memory>
#include <cpr/cpr.h>
std::shared_ptr<cpr::Session> CreateCprSession(const std::string& url) {
std::shared_ptr<cpr::Session> session = std::make_shared<cpr::Session>();
session->SetUrl(url);
session->SetProgressCallback(cpr::ProgressCallback(
[](cpr::cpr_off_t downloadTotal, cpr::cpr_off_t downloadNow, cpr::cpr_off_t uploadTotal, cpr::cpr_off_t uploadNow, intptr_t userdata) {
std::cout << "Downloaded: " << downloadTotal << " / " << downloadNow << "\n";
return true;
}));
return session;
}
int main() {
std::shared_ptr<cpr::Session> session = CreateCprSession("https://httpbin.org/get");
cpr::Response response = session->Get();
std::cout << "Response: " << response.text << "\n";
return 0;
} |
I'm keeping #999 open for the next week or so, to ensure there are no other important arguments against this approach. |
Indeed, nothing good will come of it)
Yes, thanks, in my case I decided to use unique_ptr |
Description
When moving a cpr::Session object, the curl options CURLOPT_XFERINFODATA, CURLOPT_DEBUGDATA, CURLOPT_WRITEDATA, and others are not updated.
As a result, when cpr tries to call, for example, the progress callback function, the progresscb_ of the old cpr::Session object that was moved is accessed.
Example/How to Reproduce
The sample code below is guaranteed to crash in debug mode. (In release mode, it's a matter of luck)
Possible Fix
I think it can be fixed by adding support to the constructor and assignment operator so that the necessary curl options are updated.
Where did you get it from?
Other (specify in "Additional Context/Your Environment")
Additional Context/Your Environment
The cpr was obtained from github and added to the project via add_subdirectory.
The text was updated successfully, but these errors were encountered: