Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note about freeing transaction in handle_message #3374

Merged
merged 2 commits into from May 24, 2024

Conversation

vincentfretin
Copy link
Contributor

Add note about freeing transaction after calling push_event in plugin interface documentation.

The only place this was mentioned seems to be in this comment in the janus.c

/* Send the message to the plugin (which must eventually free transaction_text and unref the two objects, body and jsep) */

and in plugin implementation like
if(root != NULL)
json_decref(root);
if(jsep != NULL)
json_decref(jsep);
g_free(transaction);

We had a memory leak for this in the rust sfu plugin I fixed in
networked-aframe/janus-plugin-sfu@4226d00
that only showed in ASan output when specifying loop_events option.
The original creator of the plugin probably overlooked this because this was not documented in plugin.h.

@lminiero
Copy link
Member

lminiero commented May 17, 2024

Add note about freeing transaction after calling push_event in plugin interface documentation.

This is incorrect. You only need to free transaction if you allocated it yourself, since push_event will treat it as a const. None of the existing plugins free it for instance, since we pass an existing transaction from a message, which typically comes from an incoming request. The transaction you must free is the one you get from the core via handle_message (which all core plugins do, and maybe you're not doing).

@vincentfretin
Copy link
Contributor Author

You're right, it's the one from handle_message I'm freeing now. I put the comment in the wrong place then, I'll update the PR.

@vincentfretin vincentfretin changed the title Add note about freeing transaction after calling push_event Add note about freeing transaction in handle_message May 20, 2024
@vincentfretin
Copy link
Contributor Author

I moved the comment at the right place.

Copy link
Member

@lminiero lminiero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, added some notes.

src/plugins/plugin.h Outdated Show resolved Hide resolved
src/plugins/plugin.h Outdated Show resolved Hide resolved
src/plugins/plugin.h Outdated Show resolved Hide resolved
@vincentfretin
Copy link
Contributor Author

I made the changes. I also added the \c for the note in push_event where I mainly copied the text from.

Copy link
Member

@lminiero lminiero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I added just a couple of minor notes after re-reading the changes, but after those I think this is good to be merged.

@@ -283,6 +283,10 @@ struct janus_plugin {
* @param[out] error An integer that may contain information about any error */
void (* const create_session)(janus_plugin_session *handle, int *error);
/*! \brief Method to handle an incoming message/request from a peer
* @note The Janus core increases the references to both the \c message and \c jsep
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that, since in this case this is a method that goes from core to plugin, it's more correct to say something like "The Janus core leaves ownership of both ...... objects to plugins. Ths means..". The "increases" part makes more sense for push_event since in that case the core does indeed increase the references to those objects, since plugins may decrease their own.

* @note The Janus core increases the references to both the \c message and \c jsep
* json_t objects. This means that you'll have to decrease your own
* reference yourself with a \c json_decref when you're done with them.
* You'll also have to free \c transaction with \c g_free.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better remove the dot at the end, after g_free, since otherwise it will appear as part of the code block. Besides, we don't have it at the end of lines in most of the other doxygen comments.

* json_t objects. This means that you'll have to decrease your own
* reference yourself with a \c json_decref after calling push_event.
* reference yourself with a \c json_decref after calling \c push_event.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here (it was there before, but now there's \c)

@vincentfretin
Copy link
Contributor Author

That's valid feedback. I did the changes.

@lminiero
Copy link
Member

Thanks! Merging 👍

@lminiero lminiero merged commit 82efb6f into meetecho:master May 24, 2024
8 checks passed
@vincentfretin vincentfretin deleted the add-doc-free-transaction branch May 24, 2024 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants