]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/mbsalign: free buffer after error [coverity scan]
authorKarel Zak <kzak@redhat.com>
Tue, 4 Oct 2016 14:14:48 +0000 (16:14 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 4 Oct 2016 14:14:48 +0000 (16:14 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/mbsalign.c

index c017ed1b3d402d4fdad2b412738ccde2efb2f9ee..731320b0741ef565bb89dfb5f2b17a658e00902f 100644 (file)
@@ -206,15 +206,16 @@ size_t mbs_safe_encode_size(size_t bytes)
 char *mbs_safe_encode(const char *s, size_t *width)
 {
        size_t sz = s ? strlen(s) : 0;
-       char *buf;
+       char *buf, *ret = NULL;;
 
        if (!sz)
                return NULL;
        buf = malloc(mbs_safe_encode_size(sz));
-       if (!buf)
-               return NULL;
-
-       return mbs_safe_encode_to_buffer(s, width, buf, NULL);
+       if (buf)
+               ret = mbs_safe_encode_to_buffer(s, width, buf, NULL);
+       if (!ret)
+               free(buf);
+       return ret;
 }
 
 #ifdef HAVE_WIDECHAR