[PATCH] mount.cifs.c: fix memory leaks in main func
Zhiqiang Liu
liuzhiqiang26 at huawei.com
Wed Jul 31 05:53:30 UTC 2019
Friendly ping ...
On 2019/7/25 14:55, Zhiqiang Liu wrote:
> From: Jiawen Liu <liujiawen10 at huawei.com>
>
> In mount.cifs module, orgoptions and mountpoint in the main func
> point to the memory allocated by func realpath and strndup respectively.
> However, they are not freed before the main func returns so that the
> memory leaks occurred.
>
> The memory leak problem is reported by LeakSanitizer tool.
> LeakSanitizer url: "https://github.com/google/sanitizers"
>
> Here I free the pointers orgoptions and mountpoint before main
> func returns.
>
> Fixes:7549ad5e7126 ("memory leaks: caused by func realpath and strndup")
> Signed-off-by: Jiawen Liu <liujiawen10 at huawei.com>
> Reported-by: Jin Du <dujin1 at huawei.com>
> Reviewed-by: Saisai Zhang <zhangsaisai at huawei.com>
> ---
> mount.cifs.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/mount.cifs.c b/mount.cifs.c
> index ae7a899..029f01a 100644
> --- a/mount.cifs.c
> +++ b/mount.cifs.c
> @@ -1830,6 +1830,7 @@ assemble_mountinfo(struct parsed_mount_info *parsed_info,
> }
>
> assemble_exit:
> + free(orgoptions);
> return rc;
> }
>
> @@ -1994,8 +1995,11 @@ int main(int argc, char **argv)
>
> /* chdir into mountpoint as soon as possible */
> rc = acquire_mountpoint(&mountpoint);
> - if (rc)
> + if (rc) {
> + free(mountpoint);
> + free(orgoptions);
> return rc;
> + }
>
> /*
> * mount.cifs does privilege separation. Most of the code to handle
> @@ -2014,6 +2018,7 @@ int main(int argc, char **argv)
> /* child */
> rc = assemble_mountinfo(parsed_info, thisprogram, mountpoint,
> orig_dev, orgoptions);
> + free(mountpoint);
> return rc;
> } else {
> /* parent */
> @@ -2149,5 +2154,6 @@ mount_exit:
> }
> free(options);
> free(orgoptions);
> + free(mountpoint);
> return rc;
> }
>
More information about the samba-technical
mailing list