919352
commit 7e60d11c1b046e54378cf79280f4a856741c8749
919352
Author: Tobias Stoeckmann <tobias@stoeckmann.org>
919352
Date:   Sat Aug 22 14:09:58 2020 +0200
919352
919352
    Close iconv in case of allocation error
919352
    
919352
    If memory allocation in strdup_locale_from_utf8 fails after calling
919352
    iconv_open, the returned conversion descriptor is not closed.
919352
919352
diff --git a/src/poptint.c b/src/poptint.c
919352
index 0cec176..3a0919a 100644
919352
--- a/src/poptint.c
919352
+++ b/src/poptint.c
919352
@@ -91,8 +91,10 @@ strdup_locale_from_utf8 (char * istr)
919352
 	size_t ob = db;
919352
 	size_t err;
919352
 
919352
-	if (dstr == NULL)
919352
+	if (dstr == NULL) {
919352
+	    (void) iconv_close(cd);
919352
 	    return NULL;
919352
+	}
919352
 	err = iconv(cd, NULL, NULL, NULL, NULL);
919352
 	while (1) {
919352
 	    *pout = '\0';
919352
commit 70011cc5763dca9a9b57e9539b465e00c9769996
919352
Author: Michal Domonkos <mdomonko@redhat.com>
919352
Date:   Mon Jul 19 14:41:03 2021 +0200
919352
919352
    Fix potential mem leak in poptReadConfigFile()
919352
    
919352
    While it seems that the actual implementation of poptReadFile()
919352
    shouldn't allocate the passed buffer (b) if the number of bytes (nb) is
919352
    zero (see the read(2) call in that function), it's still up to the
919352
    caller to take care of this resource, so let's just do that by bailing
919352
    out via "exit" where the freeing happens.
919352
    
919352
    Also initialize t to NULL to avoid freeing an undefined pointer.
919352
    
919352
    Found by Coverity.
919352
919352
diff --git a/src/poptconfig.c b/src/poptconfig.c
919352
index 8623ba2..7c52315 100644
919352
--- a/src/poptconfig.c
919352
+++ b/src/poptconfig.c
919352
@@ -344,13 +344,15 @@ int poptReadConfigFile(poptContext con, const char * fn)
919352
     char * b = NULL, *be;
919352
     size_t nb = 0;
919352
     const char *se;
919352
-    char *t, *te;
919352
+    char *t = NULL, *te;
919352
     int rc;
919352
 
919352
     if ((rc = poptReadFile(fn, &b, &nb, POPT_READFILE_TRIMNEWLINES)) != 0)
919352
 	return (errno == ENOENT ? 0 : rc);
919352
-    if (b == NULL || nb == 0)
919352
-	return POPT_ERROR_BADCONFIG;
919352
+    if (b == NULL || nb == 0) {
919352
+	rc = POPT_ERROR_BADCONFIG;
919352
+	goto exit;
919352
+    }
919352
 
919352
     if ((t = malloc(nb + 1)) == NULL)
919352
 	goto exit;