core: fix memory leak if url change fails
[project/uclient.git] / uclient.c
index d5997633273b83ee4b3c96f51592dc6be81476bb..2113d8dc795c621c43ce9631a15d3a3151d691dc 100644 (file)
--- a/uclient.c
+++ b/uclient.c
@@ -182,8 +182,10 @@ int uclient_set_url(struct uclient *cl, const char *url_str, const char *auth_st
        if (!url)
                return -1;
 
-       if (url->backend != cl->backend)
+       if (url->backend != cl->backend) {
+               free(url);
                return -1;
+       }
 
        free(cl->url);
        cl->url = url;
@@ -221,7 +223,7 @@ void uclient_free(struct uclient *cl)
        free(url);
 }
 
-int uclient_write(struct uclient *cl, char *buf, int len)
+int uclient_write(struct uclient *cl, const char *buf, int len)
 {
        if (!cl->backend->write)
                return -1;