[PATCH v2 3/4] udev: Add strdups to kill const warnings

Dan Nicholson dbn.lists at gmail.com
Thu Dec 30 06:20:12 PST 2010


On Wed, Dec 29, 2010 at 5:17 PM, Daniel Stone <daniel at fooishbar.org> wrote:
> InputAttributes wants non-const members, and while it appears safe to
> cast it, just leave it be for the moment.
>
> Signed-off-by: Daniel Stone <daniel at fooishbar.org>
> Reviewed-by: Dan Nicholson <dbn.lists at gmail.com>
> ---
>
> v2: v1 was somewhat broken, and missing NULL checks around the newly-introduced
> strdups.  Oops.
>
>  config/udev.c |   16 +++++++++++-----
>  1 files changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/config/udev.c b/config/udev.c
> index 496bfbf..01e8293 100644
> --- a/config/udev.c
> +++ b/config/udev.c
> @@ -103,7 +103,8 @@ device_added(struct udev_device *udev_device)
>             LOG_PROPERTY(ppath, "NAME", name);
>         }
>
> -        attrs.pnp_id = udev_device_get_sysattr_value(parent, "id");
> +        if (attrs.pnp_id)
> +            attrs.pnp_id = strdup(udev_device_get_sysattr_value(parent, "id"));
>         LOG_SYSATTR(ppath, "id", attrs.pnp_id);
>
>         /* construct USB ID in lowercase hex - "0000:ffff" */
> @@ -116,14 +117,15 @@ device_added(struct udev_device *udev_device)
>         }
>     }
>     if (!name)
> -        name = "(unnamed)";
> +        name = strdup("(unnamed)");
>     else
> -        attrs.product = name;
> +        attrs.product = strdup(name);
>     add_option(&options, "name", name);

Looking at this part again, we'd end up leaking the "unnamed" string
in the !name case since we don't free name anywhere. add_option does
the duping itself, so we only need to dup the name when setting
attrs.product.

--
Dan


More information about the xorg-devel mailing list