Skip to content

Commit

Permalink
Cleanup some g_free usage (#3135)
Browse files Browse the repository at this point in the history
* mqttevh: simplify g_free usage

g_free(NULL) is safe and well defined.

* rabbitmqevh: simplify g_free usage and pointer semantics

Declaring dynamically allocated strings as const char * doesn't really make sense
since they have to be cast to char * to be freed.

* sdp: simplify g_free use and drop noop NULL assignment

These variables are local and go out of scope here, so assigning NULL
is redundant as they are no longer read.
  • Loading branch information
tmatth committed Jan 4, 2023
1 parent 810e57d commit 5193315
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 46 deletions.
12 changes: 3 additions & 9 deletions src/events/janus_mqttevh.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,15 +637,9 @@ static void janus_mqttevh_client_destroy_context(janus_mqttevh_context **ptr) {

if(ctx) {
MQTTAsync_destroy(&ctx->client);
if(ctx->publish.topic != NULL) {
g_free(ctx->publish.topic);
}
if(ctx->connect.username != NULL) {
g_free(ctx->connect.username);
}
if(ctx->connect.password != NULL) {
g_free(ctx->connect.password);
}
g_free(ctx->publish.topic);
g_free(ctx->connect.username);
g_free(ctx->connect.password);
g_free(ctx);
*ptr = NULL;
}
Expand Down
40 changes: 15 additions & 25 deletions src/events/janus_rabbitmqevh.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ static amqp_bytes_t rmq_exchange;
static janus_mutex mutex;

static char *rmqhost = NULL;
static const char *vhost = NULL, *username = NULL, *password = NULL;
static const char *ssl_cacert_file = NULL;
static const char *ssl_cert_file = NULL;
static const char *ssl_key_file = NULL;
static char *vhost = NULL, *username = NULL, *password = NULL;
static char *ssl_cacert_file = NULL;
static char *ssl_cert_file = NULL;
static char *ssl_key_file = NULL;
static gboolean ssl_enable = FALSE;
static gboolean ssl_verify_peer = FALSE;
static gboolean ssl_verify_hostname = FALSE;
static const char *route_key = NULL, *exchange = NULL, *exchange_type = NULL ;
static char *route_key = NULL, *exchange = NULL, *exchange_type = NULL ;
static uint16_t heartbeat = 0;
static uint16_t rmqport = AMQP_PROTOCOL_PORT;
static gboolean declare_outgoing_queue = TRUE;
Expand Down Expand Up @@ -331,10 +331,8 @@ int janus_rabbitmqevh_init(const char *config_path) {
error:
/* If we got here, something went wrong */
success = FALSE;
if(route_key)
g_free((char *)route_key);
if(exchange)
g_free((char *)exchange);
g_free(route_key);
g_free(exchange);
/* Fall through */
done:
if(config)
Expand Down Expand Up @@ -453,22 +451,14 @@ void janus_rabbitmqevh_destroy(void) {
if(rmq_conn) {
amqp_destroy_connection(rmq_conn);
}
if(rmq_exchange.bytes)
g_free((char *)rmq_exchange.bytes);
if(rmqhost)
g_free((char *)rmqhost);
if(vhost)
g_free((char *)vhost);
if(username)
g_free((char *)username);
if(password)
g_free((char *)password);
if(ssl_cacert_file)
g_free((char *)ssl_cacert_file);
if(ssl_cert_file)
g_free((char *)ssl_cert_file);
if(ssl_key_file)
g_free((char *)ssl_key_file);
g_free(rmq_exchange.bytes);
g_free(rmqhost);
g_free(vhost);
g_free(username);
g_free(password);
g_free(ssl_cacert_file);
g_free(ssl_cert_file);
g_free(ssl_key_file);

janus_mutex_destroy(&mutex);
g_atomic_int_set(&initialized, 0);
Expand Down
16 changes: 4 additions & 12 deletions src/sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,18 +395,10 @@ int janus_sdp_process_remote(void *ice_handle, janus_sdp *remote_sdp, gboolean r
/* Missing mandatory information, failure... */
JANUS_LOG(LOG_ERR, "[%"SCNu64"] SDP missing mandatory information\n", handle->handle_id);
JANUS_LOG(LOG_ERR, "[%"SCNu64"] %p, %p, %p, %p\n", handle->handle_id, ruser, rpass, rfingerprint, rhashing);
if(ruser)
g_free(ruser);
ruser = NULL;
if(rpass)
g_free(rpass);
rpass = NULL;
if(rhashing)
g_free(rhashing);
rhashing = NULL;
if(rfingerprint)
g_free(rfingerprint);
rfingerprint = NULL;
g_free(ruser);
g_free(rpass);
g_free(rhashing);
g_free(rfingerprint);
return -2;
}
/* If we received the ICE credentials for the first time, enforce them */
Expand Down

0 comments on commit 5193315

Please sign in to comment.