Fixed memory leak
authorArmin Novak <armin.novak@gmail.com>
Sun, 16 Nov 2014 23:13:50 +0000 (00:13 +0100)
committerArmin Novak <armin.novak@gmail.com>
Sun, 16 Nov 2014 23:13:50 +0000 (00:13 +0100)
winpr/tools/makecert/makecert.c

index 8a876b2..db14195 100644 (file)
@@ -551,7 +551,12 @@ int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* pa
                        bio = BIO_new(BIO_s_mem());
 
                        if (!bio)
+                       {
+                               free(filename);
+                               free(fullpath);
+                               fclose (fp);
                                return -1;
+                       }
 
                        status = PEM_write_bio_X509(bio, context->x509);
 
@@ -562,7 +567,12 @@ int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* pa
                        status = BIO_read(bio, x509_str, length);
                
                        if (status < 0)
+                       {
+                               free(filename);
+                               free(fullpath);
+                               fclose (fp);
                                return -1;
+                       }
                
                        offset += status;
 
@@ -580,7 +590,14 @@ int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* pa
                        }
 
                        if (status < 0)
+                       {
+                               if (x509_str)
+                                       free (x509_str);
+                               free(filename);
+                               free(fullpath);
+                               fclose (fp);
                                return -1;
+                       }
                
                        length = offset;
 
@@ -594,7 +611,12 @@ int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* pa
                                bio = BIO_new(BIO_s_mem());
 
                                if (!bio)
+                               {
+                                       free(filename);
+                                       free(fullpath);
+                                       fclose (fp);
                                        return -1;
+                               }
 
                                status = PEM_write_bio_PrivateKey(bio, context->pkey, NULL, NULL, 0, NULL, NULL);
 
@@ -605,7 +627,14 @@ int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* pa
                                status = BIO_read(bio, x509_str, length);
                
                                if (status < 0)
+                               {
+                                       if (x509_str)
+                                               free(x509_str);
+                                       free(filename);
+                                       free(fullpath);
+                                       fclose (fp);
                                        return -1;
+                               }
                
                                offset += status;
 
@@ -623,7 +652,14 @@ int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* pa
                                }
 
                                if (status < 0)
+                               {
+                                       if (x509_str)
+                                               free(x509_str);
+                                       free(filename);
+                                       free(fullpath);
+                                       fclose (fp);
                                        return -1;
+                               }
                
                                length = offset;