Fix crash in post function
User data for write callback should be 'this' pointer, not some string object.
This commit is contained in:
		@@ -2,6 +2,6 @@ LDLIBS := -lcurl -lsclogging -lscterm
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
MAJOR := 1
 | 
					MAJOR := 1
 | 
				
			||||||
MINOR := 0
 | 
					MINOR := 0
 | 
				
			||||||
PATCH := 0
 | 
					PATCH := 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GENERATELIBHEADER := 1
 | 
					GENERATELIBHEADER := 1
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,5 @@
 | 
				
			|||||||
#include "requester.hpp"
 | 
					#include "requester.hpp"
 | 
				
			||||||
#include <curl/curl.h>
 | 
					#include <curl/curl.h>
 | 
				
			||||||
#include <vector>
 | 
					 | 
				
			||||||
#include <cstring>
 | 
					#include <cstring>
 | 
				
			||||||
#include <stdexcept>
 | 
					#include <stdexcept>
 | 
				
			||||||
#include <utility>
 | 
					#include <utility>
 | 
				
			||||||
@@ -73,9 +72,7 @@ std::string requester::post(const std::string& url, const std::string& json) {
 | 
				
			|||||||
    headers = curl_slist_append(headers, "Content-Type: application/json");
 | 
					    headers = curl_slist_append(headers, "Content-Type: application/json");
 | 
				
			||||||
    std::unique_ptr<struct curl_slist, void(*)(struct curl_slist*)> hdrs {headers, curl_slist_free_all};
 | 
					    std::unique_ptr<struct curl_slist, void(*)(struct curl_slist*)> hdrs {headers, curl_slist_free_all};
 | 
				
			||||||
    curl_easy_setopt(_h.get(), CURLOPT_HTTPHEADER, headers);
 | 
					    curl_easy_setopt(_h.get(), CURLOPT_HTTPHEADER, headers);
 | 
				
			||||||
 | 
					    curl_easy_setopt(_h.get(), CURLOPT_WRITEDATA, this);
 | 
				
			||||||
    std::string response;
 | 
					 | 
				
			||||||
    curl_easy_setopt(_h.get(), CURLOPT_WRITEDATA, &response);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    auto success = curl_easy_perform(_h.get());
 | 
					    auto success = curl_easy_perform(_h.get());
 | 
				
			||||||
    if (success != CURLE_OK) {
 | 
					    if (success != CURLE_OK) {
 | 
				
			||||||
@@ -83,5 +80,5 @@ std::string requester::post(const std::string& url, const std::string& json) {
 | 
				
			|||||||
        oss << "could not post data: " << curl_easy_strerror(success);
 | 
					        oss << "could not post data: " << curl_easy_strerror(success);
 | 
				
			||||||
        throw std::runtime_error {oss.str()};
 | 
					        throw std::runtime_error {oss.str()};
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return response;
 | 
					    return _text;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user