WTP can join w/o any memory leaks

This commit is contained in:
2022-08-15 16:31:26 +02:00
parent df5e2bcbb7
commit a051ba41de
17 changed files with 119 additions and 99 deletions

View File

@ -544,6 +544,17 @@ uint8_t cw_cfg_get_byte(cw_Cfg_t * cfg, char *key, uint8_t def)
return v.val.byte;
}
uint8_t cw_cfg_get_byte_l(cw_Cfg_t ** cfgs, char *key, uint8_t def)
{
struct cw_Val v;
memset(&v,0,sizeof(struct cw_Val));
const char *s = cw_cfg_get_l(cfgs,key,NULL);
if (s==NULL)
return def;
CW_TYPE_BYTE->from_str(&v,s);
return v.val.byte;
}
uint16_t cw_cfg_get_word(cw_Cfg_t * cfg, char *key, uint16_t def)

View File

@ -43,6 +43,7 @@ void cw_cfg_copy(cw_Cfg_t *src, cw_Cfg_t *dst);
void cw_cfg_destroy(cw_Cfg_t *cfg);
void cw_cfg_clear(cw_Cfg_t *cfg);
int cw_cfg_base_exists(cw_Cfg_t * cfg, const char *key);
uint8_t cw_cfg_get_byte_l(cw_Cfg_t ** cfgs, char *key, uint8_t def);

View File

@ -22,7 +22,7 @@
#include "msgset.h"
#include "mavltypes.h"
#include "dtls.h"
/**
@ -937,6 +937,7 @@ int cw_read_messages(struct cw_Conn *conn)
*/
void conn_destroy(struct cw_Conn * conn)
{
dtls_shutdown(conn);
if (conn->fragman)
fragman_destroy(conn->fragman);
if (conn->q)
@ -954,6 +955,8 @@ void conn_destroy(struct cw_Conn * conn)
if (conn->local_cfg)
cw_cfg_destroy(conn->local_cfg);
free(conn);
}

View File

@ -127,6 +127,11 @@ static int bread(cw_Cfg_t *cfg, const char * key, const uint8_t *src, int len, c
return rc;
}
static int bwrite(cw_Cfg_t ** cfgs, const char *key, uint8_t *dst, const void * param)
{
return cw_generic_write_l(cfgs,CW_TYPE_IPADDRESS,key,dst,param);
}
const struct cw_Type cw_type_ipaddress = {
@ -141,6 +146,7 @@ const struct cw_Type cw_type_ipaddress = {
get_type_name,
NULL,
bread,
bwrite,
};

View File

@ -31,6 +31,7 @@
#define dtls_connect dtls_openssl_connect
#define dtls_shutdown dtls_openssl_shutdown
#define dtls_get_cipher dtls_openssl_get_cipher
#define dtls_data_destroy dtls_openssl_data_destroy
#else
#include "dtls_gnutls.h"
#define dtls_init dtls_gnutls_init

View File

@ -207,11 +207,14 @@ void dtls_openssl_data_destroy(struct dtls_openssl_data * d){
if (!d)
return;
if (d->ctx)
SSL_CTX_free(d->ctx);
if (d->ssl)
SSL_free(d->ssl);
if (d->ctx)
SSL_CTX_free(d->ctx);
if (d->biomethod)
BIO_meth_free(d->biomethod);
free(d);

View File

@ -38,6 +38,7 @@ struct dtls_openssl_data{
SSL_CTX * ctx;
SSL * ssl;
BIO * bio;
BIO_METHOD * biomethod;
uint8_t buffer[4096];
int len;
int pos;
@ -78,6 +79,7 @@ extern int dtls_openssl_log_error_queue(const char *txt);
extern BIO_METHOD * dtls_openssl_bio_method();
extern int dtls_openssl_shutdown(struct cw_Conn *conn);
extern void dtls_openssl_data_destroy(struct dtls_openssl_data * d);
/**
* @}

View File

@ -49,12 +49,15 @@ dtls_openssl_connect(struct cw_Conn *conn)
dtls_openssl_data_create(conn, DTLS_client_method(),
biomethod);
cw_dbg(DBG_DTLS_BIO, "DTLS Connect call 2");
d = (struct dtls_openssl_data *) conn->dtls_data;
if (!d)
return 0;
d->biomethod = biomethod;
/*
if (conn->dtls_psk)
SSL_set_psk_client_callback(d->ssl, psk_client_cb);