Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> --- src/media.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/media.c b/src/media.c index 657b6c4..6c03369 100644 --- a/src/media.c +++ b/src/media.c @@ -403,6 +403,12 @@ static int media_enum_entities(struct media_private *priv) return ret; } +static inline void close_and_free(struct media_private *priv) +{ + free(priv); + media_close(priv->media); +} + struct media_device *media_open(const char *name, int verbose) { struct media_device *media; @@ -440,8 +446,7 @@ struct media_device *media_open(const char *name, int verbose) ret = media_udev_open(priv); if (ret < 0) { printf("%s: Can't get udev context\n", __func__); - free(priv); - media_close(media); + close_and_free(priv); return NULL; } @@ -457,8 +462,7 @@ struct media_device *media_open(const char *name, int verbose) if (ret < 0) { printf("%s: Unable to enumerate entities for device %s (%s)\n", __func__, name, strerror(-ret)); - free(priv); - media_close(media); + close_and_free(priv); return NULL; } @@ -471,8 +475,7 @@ struct media_device *media_open(const char *name, int verbose) if (ret < 0) { printf("%s: Unable to enumerate pads and linksfor device %s\n", __func__, name); - free(priv); - media_close(media); + close_and_free(priv); return NULL; } -- 1.7.5.4 -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html