@@ -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;
}
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> --- src/media.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)