Signed-off-by: David Goulet <dgoulet@efficios.com>
DBG("Application socket %d is being teardown. Abort event notify",
sock);
ret = 0;
DBG("Application socket %d is being teardown. Abort event notify",
sock);
ret = 0;
if (!ua_chan) {
DBG("Application channel is being teardown. Abort event notify");
ret = 0;
if (!ua_chan) {
DBG("Application channel is being teardown. Abort event notify");
ret = 0;
} else {
/* Get current already assigned values. */
type = chan_reg->header_type;
} else {
/* Get current already assigned values. */
type = chan_reg->header_type;
+ free(fields);
+ /* Set to NULL so the error path does not do a double free. */
+ fields = NULL;
}
/* Channel id is set during the object creation. */
chan_id = chan_reg->chan_id;
}
/* Channel id is set during the object creation. */
chan_id = chan_reg->chan_id;
pthread_mutex_unlock(®istry->lock);
error_rcu_unlock:
rcu_read_unlock();
pthread_mutex_unlock(®istry->lock);
error_rcu_unlock:
rcu_read_unlock();
+ if (ret) {
+ free(fields);
+ }
DBG("Application socket %d is being teardown. Abort event notify",
sock);
ret = 0;
DBG("Application socket %d is being teardown. Abort event notify",
sock);
ret = 0;
+ free(sig);
+ free(fields);
+ free(model_emf_uri);
if (!ua_chan) {
DBG("Application channel is being teardown. Abort event notify");
ret = 0;
if (!ua_chan) {
DBG("Application channel is being teardown. Abort event notify");
ret = 0;
+ free(sig);
+ free(fields);
+ free(model_emf_uri);
pthread_mutex_lock(®istry->lock);
pthread_mutex_lock(®istry->lock);
+ /*
+ * From this point on, this call acquires the ownership of the sig, fields
+ * and model_emf_uri meaning any free are done inside it if needed. These
+ * three variables MUST NOT be read/write after this.
+ */
ret_code = ust_registry_create_event(registry, chan_reg_key,
sobjd, cobjd, name, sig, nr_fields, fields, loglevel,
model_emf_uri, ua_sess->buffer_type, &event_id);
ret_code = ust_registry_create_event(registry, chan_reg_key,
sobjd, cobjd, name, sig, nr_fields, fields, loglevel,
model_emf_uri, ua_sess->buffer_type, &event_id);
- /* Add event to the UST registry coming from the notify socket. */
+ /*
+ * Add event to the UST registry coming from the notify socket. This
+ * call will free if needed the sig, fields and model_emf_uri. This
+ * code path loses the ownsership of these variables and transfer them
+ * to the this function.
+ */
ret = add_event_ust_registry(sock, sobjd, cobjd, name, sig, nr_fields,
fields, loglevel, model_emf_uri);
if (ret < 0) {
ret = add_event_ust_registry(sock, sobjd, cobjd, name, sig, nr_fields,
fields, loglevel, model_emf_uri);
if (ret < 0) {
- free(sig);
- free(model_emf_uri);
- free(fields);
+ /*
+ * The fields ownership are transfered to this function call meaning
+ * that if needed it will be freed. After this, it's invalid to access
+ * fields or clean it up.
+ */
ret = reply_ust_register_channel(sock, sobjd, cobjd, nr_fields,
fields);
if (ret < 0) {
ret = reply_ust_register_channel(sock, sobjd, cobjd, nr_fields,
fields);
if (ret < 0) {
assert(sig);
assert(event_id_p);
assert(sig);
assert(event_id_p);
/*
* This should not happen but since it comes from the UST tracer, an
* external party, don't assert and simply validate values.
*/
if (session_objd < 0 || channel_objd < 0) {
ret = -EINVAL;
/*
* This should not happen but since it comes from the UST tracer, an
* external party, don't assert and simply validate values.
*/
if (session_objd < 0 || channel_objd < 0) {
ret = -EINVAL;
chan = ust_registry_channel_find(session, chan_key);
if (!chan) {
ret = -EINVAL;
chan = ust_registry_channel_find(session, chan_key);
if (!chan) {
ret = -EINVAL;
}
/* Check if we've reached the maximum possible id. */
if (ust_registry_is_max_id(chan->used_event_id)) {
ret = -ENOENT;
}
/* Check if we've reached the maximum possible id. */
if (ust_registry_is_max_id(chan->used_event_id)) {
ret = -ENOENT;
}
event = alloc_event(session_objd, channel_objd, name, sig, nr_fields,
fields, loglevel, model_emf_uri);
if (!event) {
ret = -ENOMEM;
}
event = alloc_event(session_objd, channel_objd, name, sig, nr_fields,
fields, loglevel, model_emf_uri);
if (!event) {
ret = -ENOMEM;
}
DBG3("UST registry creating event with event: %s, sig: %s, id: %u, "
}
DBG3("UST registry creating event with event: %s, sig: %s, id: %u, "
rcu_read_unlock();
return 0;
rcu_read_unlock();
return 0;
+error_free:
+ free(sig);
+ free(fields);
+ free(model_emf_uri);
error_unlock:
rcu_read_unlock();
error_unlock:
rcu_read_unlock();
destroy_event(event);
return ret;
}
destroy_event(event);
return ret;
}