summaryrefslogtreecommitdiff
path: root/libbridge/src/main/cpp
diff options
context:
space:
mode:
authorCzarek Nakamoto <cyjan@mrcyjanek.net>2023-12-30 16:50:49 +0100
committerCzarek Nakamoto <cyjan@mrcyjanek.net>2023-12-30 16:50:49 +0100
commit8d9b26f371f05470d636a1cc68758e973e63a8ce (patch)
tree80ea013c1af041d9ccf757de8add564a72ed9e10 /libbridge/src/main/cpp
parent3eb7c3c5f822cbe8bfe0bf7b678d85d748a91fe2 (diff)
fix memory
Diffstat (limited to 'libbridge/src/main/cpp')
-rw-r--r--libbridge/src/main/cpp/wallet2_api_c.cpp90
1 files changed, 75 insertions, 15 deletions
diff --git a/libbridge/src/main/cpp/wallet2_api_c.cpp b/libbridge/src/main/cpp/wallet2_api_c.cpp
index 3dcb637..b756342 100644
--- a/libbridge/src/main/cpp/wallet2_api_c.cpp
+++ b/libbridge/src/main/cpp/wallet2_api_c.cpp
@@ -33,7 +33,11 @@ int MONERO_PendingTransaction_status(void* pendingTx_ptr) {
}
const char* MONERO_PendingTransaction_errorString(void* pendingTx_ptr) {
Monero::PendingTransaction *pendingTx = reinterpret_cast<Monero::PendingTransaction*>(pendingTx_ptr);
- return pendingTx->errorString().c_str();
+ std::string str = pendingTx->errorString();
+ const std::string::size_type size = str.size();
+ char *buffer = new char[size + 1]; //we need extra char for NUL
+ memcpy(buffer, str.c_str(), size + 1);
+ return buffer;
}
bool MONERO_PendingTransaction_commit(void* pendingTx_ptr, const char* filename, bool overwrite) {
Monero::PendingTransaction *pendingTx = reinterpret_cast<Monero::PendingTransaction*>(pendingTx_ptr);
@@ -87,7 +91,11 @@ uint64_t MONERO_TransactionInfo_blockHeight(void* txInfo_ptr) {
}
const char* MONERO_TransactionInfo_description(void* txInfo_ptr) {
Monero::TransactionInfo *txInfo = reinterpret_cast<Monero::TransactionInfo*>(txInfo_ptr);
- return txInfo->description().c_str();
+ std::string str = txInfo->description();
+ const std::string::size_type size = str.size();
+ char *buffer = new char[size + 1]; //we need extra char for NUL
+ memcpy(buffer, str.c_str(), size + 1);
+ return buffer;
}
uint32_t MONERO_TransactionInfo_subaddrAccount(void* txInfo_ptr) {
Monero::TransactionInfo *txInfo = reinterpret_cast<Monero::TransactionInfo*>(txInfo_ptr);
@@ -95,7 +103,11 @@ uint32_t MONERO_TransactionInfo_subaddrAccount(void* txInfo_ptr) {
}
const char* MONERO_TransactionInfo_label(void* txInfo_ptr) {
Monero::TransactionInfo *txInfo = reinterpret_cast<Monero::TransactionInfo*>(txInfo_ptr);
- return txInfo->label().c_str();
+ std::string str = txInfo->label();
+ const std::string::size_type size = str.size();
+ char *buffer = new char[size + 1]; //we need extra char for NUL
+ memcpy(buffer, str.c_str(), size + 1);
+ return buffer;
}
uint64_t MONERO_TransactionInfo_confirmations(void* txInfo_ptr) {
Monero::TransactionInfo *txInfo = reinterpret_cast<Monero::TransactionInfo*>(txInfo_ptr);
@@ -107,7 +119,11 @@ uint64_t MONERO_TransactionInfo_unlockTime(void* txInfo_ptr) {
}
const char* MONERO_TransactionInfo_hash(void* txInfo_ptr) {
Monero::TransactionInfo *txInfo = reinterpret_cast<Monero::TransactionInfo*>(txInfo_ptr);
- return txInfo->hash().c_str();
+ std::string str = txInfo->hash();
+ const std::string::size_type size = str.size();
+ char *buffer = new char[size + 1]; //we need extra char for NUL
+ memcpy(buffer, str.c_str(), size + 1);
+ return buffer;
}
uint64_t MONERO_TransactionInfo_timestamp(void* txInfo_ptr) {
Monero::TransactionInfo *txInfo = reinterpret_cast<Monero::TransactionInfo*>(txInfo_ptr);
@@ -115,7 +131,11 @@ uint64_t MONERO_TransactionInfo_timestamp(void* txInfo_ptr) {
}
const char* MONERO_TransactionInfo_paymentId(void* txInfo_ptr) {
Monero::TransactionInfo *txInfo = reinterpret_cast<Monero::TransactionInfo*>(txInfo_ptr);
- return txInfo->paymentId().c_str();
+ std::string str = txInfo->paymentId();
+ const std::string::size_type size = str.size();
+ char *buffer = new char[size + 1]; //we need extra char for NUL
+ memcpy(buffer, str.c_str(), size + 1);
+ return buffer;
}
// TransactionHistory
@@ -141,7 +161,11 @@ void MONERO_TransactionHistory_setTxNote(void* txHistory_ptr, const char* txid,
const char* MONERO_Wallet_seed(void* wallet_ptr) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
- return wallet->seed().c_str();
+ std::string str = wallet->seed();
+ const std::string::size_type size = str.size();
+ char *buffer = new char[size + 1]; //we need extra char for NUL
+ memcpy(buffer, str.c_str(), size + 1);
+ return buffer;
}
int MONERO_Wallet_status(void* wallet_ptr) {
@@ -151,32 +175,56 @@ int MONERO_Wallet_status(void* wallet_ptr) {
const char* MONERO_Wallet_errorString(void* wallet_ptr) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
- return wallet->errorString().c_str();
+ std::string str = wallet->errorString();
+ const std::string::size_type size = str.size();
+ char *buffer = new char[size + 1]; //we need extra char for NUL
+ memcpy(buffer, str.c_str(), size + 1);
+ return buffer;
}
const char* MONERO_Wallet_address(void* wallet_ptr, uint64_t accountIndex, uint64_t addressIndex) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
- return wallet->address(accountIndex, addressIndex).c_str();
+ std::string str = wallet->address(accountIndex, addressIndex);
+ const std::string::size_type size = str.size();
+ char *buffer = new char[size + 1]; //we need extra char for NUL
+ memcpy(buffer, str.c_str(), size + 1);
+ return buffer;
}
const char* MONERO_Wallet_secretViewKey(void* wallet_ptr) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
- return wallet->secretViewKey().c_str();
+ std::string str = wallet->secretViewKey();
+ const std::string::size_type size = str.size();
+ char *buffer = new char[size + 1]; //we need extra char for NUL
+ memcpy(buffer, str.c_str(), size + 1);
+ return buffer;
}
const char* MONERO_Wallet_publicViewKey(void* wallet_ptr) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
- return wallet->publicViewKey().c_str();
+ std::string str = wallet->publicViewKey();
+ const std::string::size_type size = str.size();
+ char *buffer = new char[size + 1]; //we need extra char for NUL
+ memcpy(buffer, str.c_str(), size + 1);
+ return buffer;
}
const char* MONERO_Wallet_secretSpendKey(void* wallet_ptr) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
- return wallet->secretSpendKey().c_str();
+ std::string str = wallet->secretSpendKey();
+ const std::string::size_type size = str.size();
+ char *buffer = new char[size + 1]; //we need extra char for NUL
+ memcpy(buffer, str.c_str(), size + 1);
+ return buffer;
}
const char* MONERO_Wallet_publicSpendKey(void* wallet_ptr) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
- return wallet->publicSpendKey().c_str();
+ std::string str = wallet->publicSpendKey();
+ const std::string::size_type size = str.size();
+ char *buffer = new char[size + 1]; //we need extra char for NUL
+ memcpy(buffer, str.c_str(), size + 1);
+ return buffer;
}
void MONERO_Wallet_stop(void* wallet_ptr) {
@@ -262,7 +310,11 @@ bool MONERO_Wallet_synchronized(void* wallet_ptr) {
}
const char* MONERO_Wallet_displayAmount(uint64_t amount) {
// Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
- return Monero::Wallet::displayAmount(amount).c_str();
+ std::string str = Monero::Wallet::displayAmount(amount);
+ const std::string::size_type size = str.size();
+ char *buffer = new char[size + 1]; //we need extra char for NUL
+ memcpy(buffer, str.c_str(), size + 1);
+ return buffer;
}
bool MONERO_Wallet_addressValid(const char* str, int nettype) {
// Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
@@ -322,7 +374,11 @@ void MONERO_Wallet_addSubaddress(void* wallet_ptr, uint32_t accountIndex, const
}
const char* MONERO_Wallet_getSubaddressLabel(void* wallet_ptr, uint32_t accountIndex, uint32_t addressIndex) {
Monero::Wallet *wallet = reinterpret_cast<Monero::Wallet*>(wallet_ptr);
- return wallet->getSubaddressLabel(accountIndex, addressIndex).c_str();
+ std::string str = wallet->getSubaddressLabel(accountIndex, addressIndex);
+ const std::string::size_type size = str.size();
+ char *buffer = new char[size + 1]; //we need extra char for NUL
+ memcpy(buffer, str.c_str(), size + 1);
+ return buffer;
}
void MONERO_Wallet_setSubaddressLabel(void* wallet_ptr, uint32_t accountIndex, uint32_t addressIndex, const char* label) {
@@ -428,7 +484,11 @@ bool MONERO_WalletManager_walletExists(const char* path) {
return Monero::WalletManagerFactory::getWalletManager()->walletExists(std::string(path));
}
const char* MONERO_WalletManager_errorString() {
- return Monero::WalletManagerFactory::getWalletManager()->errorString().c_str();
+ std::string str = Monero::WalletManagerFactory::getWalletManager()->errorString();
+ const std::string::size_type size = str.size();
+ char *buffer = new char[size + 1]; //we need extra char for NUL
+ memcpy(buffer, str.c_str(), size + 1);
+ return buffer;
}
void MONERO_WalletManager_setDaemonAddress(const char* address) {