str_destroy

This commit is contained in:
Timerix 2025-11-26 17:06:32 +05:00
parent 2686ca6bcf
commit f5169e8a8f
10 changed files with 25 additions and 22 deletions

View File

@ -1,17 +1,20 @@
# tcp-chat
## Build
1. Clone the repository with submodules.
1. Clone this repository with submodules.
```
git clone --recurse-submodules --depth 0 https://timerix.ddns.net/git/Timerix/tcp-chat.git
```
2. Install [cbuild](https://timerix.ddns.net/git/Timerix/cbuild).
2. Install [cbuild](https://timerix.ddns.net/git/Timerix/cbuild) version specified in `project.config`.
3. Build executable
```
cd tcp-chat
cbuild build_exec
```
## Usage
**Client:**
```sh

2
dependencies/tlibc vendored

@ -1 +1 @@
Subproject commit 4c97787c27af5b7867c8a1262a3383a84a1d4957
Subproject commit 8a40caaf1044f9fe2c327c4d3c60a3310efd6142

View File

@ -57,8 +57,8 @@ Result(void) ClientCLI_run(ClientCLI* self) {
str username = str_null, password = str_null;
try_void(ClientCLI_askUserNameAndPassword(&username, &password));
Defer(
str_free(username);
str_free(password);
str_destroy(username);
str_destroy(password);
);
Client_free(self->client);
try(self->client, p, Client_create(username, password));
@ -85,7 +85,7 @@ Result(void) ClientCLI_run(ClientCLI* self) {
Error_addCallPos(com_result.error, ErrorCallPos_here());
str e_str = Error_toStr(com_result.error);
printf("\n"FMT_str"\n", e_str.len, e_str.data);
str_free(e_str);
str_destroy(e_str);
Error_free(com_result.error);
}
}

View File

@ -31,11 +31,11 @@ Result(void) run_RsaGenStdin(u32 key_size) {
str sk_str = RSA_serializePrivateKey_base64(&sk);
printf("rsa_private_key = %s\n", sk_str.data);
str_free(sk_str);
str_destroy(sk_str);
str pk_str = RSA_serializePublicKey_base64(&pk);
printf("\nrsa_public_key = %s\n", pk_str.data);
str_free(pk_str);
str_destroy(pk_str);
Return RESULT_VOID;
}
@ -54,11 +54,11 @@ Result(void) run_RsaGenRandom(u32 key_size) {
str sk_str = RSA_serializePrivateKey_base64(&sk);
printf("rsa_private_key = %s\n", sk_str.data);
str_free(sk_str);
str_destroy(sk_str);
str pk_str = RSA_serializePublicKey_base64(&pk);
printf("\nrsa_public_key = %s\n", pk_str.data);
str_free(pk_str);
str_destroy(pk_str);
Return RESULT_VOID;
}

View File

@ -8,8 +8,8 @@ void ServerConnection_close(ServerConnection* self){
EncryptedSocketTCP_destroy(&self->sock);
Array_u8_destroy(&self->token);
Array_u8_destroy(&self->session_key);
str_free(self->server_name);
str_free(self->server_description);
str_destroy(self->server_name);
str_destroy(self->server_description);
free(self);
}

View File

@ -5,7 +5,7 @@ void Client_free(Client* self){
if(!self)
return;
str_free(self->username);
str_destroy(self->username);
Array_u8_destroy(&self->user_data_key);
ServerConnection_close(self->conn);
free(self);

View File

@ -49,9 +49,9 @@ static void Table_close(Table* t){
return;
fclose(t->table_file);
fclose(t->changes_file);
str_free(t->name);
str_free(t->table_file_path);
str_free(t->changes_file_path);
str_destroy(t->name);
str_destroy(t->table_file_path);
str_destroy(t->changes_file_path);
pthread_mutex_destroy(&t->mutex);
Array_u8_destroy(&t->enc_buf);
free(t);
@ -207,7 +207,7 @@ static Result(void) Table_validateRowSize(Table* t, u32 row_size){
void idb_close(IncrementalDB* db){
if(db == NULL)
return;
str_free(db->db_dir);
str_destroy(db->db_dir);
Array_u8_destroy(&db->aes_key);
HashMap_destroy(&db->tables_map);
pthread_mutex_destroy(&db->mutex);

View File

@ -26,7 +26,7 @@ declare_RequestHandler(Login)
str username_str = str_null;
str name_error_str = validateUsername_cstr(req.username, &username_str);
if(name_error_str.data){
Defer(str_free(name_error_str));
Defer(str_destroy(name_error_str));
try_void(sendErrorMessage(log_ctx, conn, res_head,
LogSeverity_Warn,
name_error_str

View File

@ -26,7 +26,7 @@ declare_RequestHandler(Register)
str username_str = str_null;
str name_error_str = validateUsername_cstr(req.username, &username_str);
if(name_error_str.data){
Defer(str_free(name_error_str));
Defer(str_destroy(name_error_str));
try_void(sendErrorMessage(log_ctx, conn, res_head,
LogSeverity_Warn,
name_error_str

View File

@ -14,8 +14,8 @@ void Server_free(Server* self){
if(!self)
return;
str_free(self->name);
str_free(self->description);
str_destroy(self->name);
str_destroy(self->description);
RSA_destroyPrivateKey(&self->rsa_sk);
RSA_destroyPublicKey(&self->rsa_pk);
@ -204,7 +204,7 @@ static void* handleConnection(void* _args){
Error_addCallPos(r.error, ErrorCallPos_here());
str e_str = Error_toStr(r.error);
logError(FMT_str, e_str.len, e_str.data);
str_free(e_str);
str_destroy(e_str);
Error_free(r.error);
}