Skip to content
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

Fix leak ref #49 #52

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/adaR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ std::string charsub(const ada_string stringi) {
const char* res = stringi.data;
size_t len = stringi.length;
ada_owned_string stringi_new = ada_idna_to_unicode(res, len);
res = stringi_new.data;
len = stringi_new.length;
return std::string(res, 0, len);
std::string_view output(stringi_new.data, stringi_new.length);
std::string output2 = {output.begin(), output.end()};
ada_free_owned_string(stringi_new);
return output2;
}

// [[Rcpp::export]]
Expand All @@ -24,8 +25,8 @@ DataFrame Rcpp_ada_parse(const CharacterVector& input_vec) {
CharacterVector hash(n);
for (unsigned int i = 0; i < n; i++) {
String s = input_vec[i];
const char* input = s.get_cstring();
ada_url url = ada_parse(input, std::strlen(input));
std::string_view input(s.get_cstring());
ada_url url = ada_parse(input.data(), input.length());
if (ada_is_valid(url)) {
href[i] = charsub(ada_get_href(url));
protocol[i] = charsub(ada_get_protocol(url));
Expand All @@ -49,6 +50,7 @@ DataFrame Rcpp_ada_parse(const CharacterVector& input_vec) {
search[i] = NA_STRING;
hash[i] = NA_STRING;
}
ada_free(url);
}
return (DataFrame::create(Named("href") = href, _["protocol"] = protocol,
_["username"] = username, _["password"] = password,
Expand All @@ -63,13 +65,14 @@ LogicalVector Rcpp_ada_has(const CharacterVector& url_vec, std::function<bool(ad
LogicalVector out(n);
for (unsigned int i = 0; i < n; i++) {
String s = url_vec[i];
const char* input = s.get_cstring();
ada_url url = ada_parse(input, std::strlen(input));
std::string_view input(s.get_cstring());
ada_url url = ada_parse(input.data(), input.length());
if (!ada_is_valid(url)) {
out[i] = NA_LOGICAL;
} else {
out[i] = func(url);
}
ada_free(url);
}
return out;
}
Expand Down Expand Up @@ -120,13 +123,14 @@ CharacterVector Rcpp_ada_get(const CharacterVector& url_vec, std::function<ada_s
CharacterVector out(n);
for (int i = 0; i < url_vec.length(); i++) {
String s = url_vec[i];
const char* input = s.get_cstring();
ada_url url = ada_parse(input, std::strlen(input));
std::string_view input(s.get_cstring());
ada_url url = ada_parse(input.data(), input.length());
if (!ada_is_valid(url)) {
out[i] = NA_STRING;
} else {
out[i] = charsub(func(url));
}
ada_free(url);
}
return (out);
}
Expand Down