Free the memory allocated for gadget/config/function structure
when faild to create suitable directory.

Signed-off-by: Krzysztof Opasiak <k.opas...@samsung.com>
---
 src/usbg.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/usbg.c b/src/usbg.c
index e222392..a7f8780 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -513,6 +513,7 @@ struct gadget *usbg_create_gadget(struct state *s, char 
*name,
        ret = mkdir(gpath, S_IRWXU|S_IRWXG|S_IRWXO);
        if (ret < 0) {
                ERRORNO("%s\n", gpath);
+               free(g);
                return NULL;
        }
 
@@ -645,6 +646,7 @@ struct function *usbg_create_function(struct gadget *g, 
enum function_type type,
        ret = mkdir(fpath, S_IRWXU|S_IRWXG|S_IRWXO);
        if (ret < 0) {
                ERRORNO("%s\n", fpath);
+               free(f);
                return NULL;
        }
 
@@ -699,6 +701,7 @@ struct config *usbg_create_config(struct gadget *g, char 
*name)
        ret = mkdir(cpath, S_IRWXU|S_IRWXG|S_IRWXO);
        if (ret < 0) {
                ERRORNO("%s\n", cpath);
+               free(c);
                return NULL;
        }
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to