[PATCH 05/12] libusbg: Fix memory leak when unable to create directory.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx>
---
 src/gadget.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/gadget.c b/src/gadget.c
index aea9b2e..f613c3e 100644
--- a/src/gadget.c
+++ b/src/gadget.c
@@ -513,6 +513,7 @@ struct gadget *gadget_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 *gadget_create_function(struct gadget *g, enum function_type typ
 	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 *gadget_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 majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux