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

samba.c: popen() leaks via stderr #164

Merged
merged 1 commit into from
Aug 22, 2017
Merged

Conversation

bp0
Copy link
Collaborator

@bp0 bp0 commented Aug 16, 2017

Part of #162: Change samba.c to use g_spawn_command_line_sync() instead of popen() to prevent leaks via stderr.
Prevents this message from appearing:

net usershare: cannot open usershare directory /var/lib/samba/usershares. Error No such file or directory
Please ask your system administrator to enable user sharing.

The problem is that I have no "usershares", so I didn't test if it is otherwise still working. Will someone who does test that?

gsize length;

spawned = g_spawn_command_line_sync("net usershare list",
&out, &err, &status, NULL);
Copy link
Owner

Choose a reason for hiding this comment

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

If stderr is not required, you can pass NULL instead of &err; then there's no need to free() it below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It appears that if you pass NULL, then stderr will still leak.

Copy link
Owner

Choose a reason for hiding this comment

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

If it's leaking, it's a bug in GLib. It's marked as optional in the documentation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If NULL is passed, the following message appears in Terminal when Shared Directories is selected:

net usershare: cannot open usershare directory /var/lib/samba/usershares. Error No such file or directory
Please ask your system administrator to enable user sharing.

I don't know, but I think it could still be optional and just forward stderr to the application's stderr if it is NULL.
When it is captured in a string, the message does not appear in Terminal.

Copy link
Owner

Choose a reason for hiding this comment

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

Ah, I see. LGTM, then.

Copy link
Owner

@lpereira lpereira left a comment

Choose a reason for hiding this comment

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

Patch LGTM, just a minor comment.

@bp0 bp0 force-pushed the popen-samba branch 2 times, most recently from 0ca5ae0 to 9ff175a Compare August 16, 2017 18:28
Signed-off-by: Burt P <pburt0@gmail.com>
@lpereira lpereira merged commit 96be574 into lpereira:master Aug 22, 2017
@lpereira
Copy link
Owner

Merged, thanks!

@bp0 bp0 deleted the popen-samba branch August 25, 2017 23:13
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.

2 participants