Fied memory leaks
authorRobert Pengelly <robertapengelly@hotmail.com>
Sun, 1 Mar 2026 11:04:10 +0000 (11:04 +0000)
committerRobert Pengelly <robertapengelly@hotmail.com>
Sun, 1 Mar 2026 11:04:10 +0000 (11:04 +0000)
include/xz.h
libxz/xz_dec_lzma2.c
report.c
unxz.c

index 7e1ccd444ce19ac790d7b9f3e8ca0021a6d9551a..11c7a36b090782c2d5f9976de30e0386811e30f2 100755 (executable)
@@ -241,4 +241,4 @@ extern void xz_crc64_init (void);
  */
 extern uint64_t xz_crc64 (const uint8_t *buf, uint64_t size, uint64_t crc);
 
-#endif      /* _XZ_H */
\ No newline at end of file
+#endif      /* _XZ_H */
index 1f2deb441ea3711f24017c75574f1975e1a9d1e7..a4dd2e7783031442509939c73bab0419901fdf0e 100755 (executable)
@@ -341,7 +341,7 @@ struct xz_dec_lzma2 {
  * Reset the dictionary state. When in single-call mode, set up the beginning
  * of the dictionary to point to the actual output buffer.
  */
-static void dict_reset(struct dictionary *dict, struct xz_buf *b) {
+static void dict_reset (struct dictionary *dict, struct xz_buf *b) {
 
     if (DEC_IS_SINGLE (dict->mode)) {
     
index 8e128ef31f46400f43a7afab03f4526adf5fcc2c..b30b515c4703e607e0182757afe9ccaf441c510e 100755 (executable)
--- a/report.c
+++ b/report.c
@@ -17,7 +17,11 @@ static int OriginalConsoleColor = -1;
 
 static void reset_console_color (void) {
 
-#if     defined (_WIN32)
+#if     defined (unix) || defined (__unix) || defined (__unix__) || defined (__APPLE__)
+
+    fprintf (stderr, "\033[0m");
+
+#elif   defined (_WIN32)
 
     HANDLE hStdError = GetStdHandle (STD_ERROR_HANDLE);
     
@@ -26,17 +30,17 @@ static void reset_console_color (void) {
     SetConsoleTextAttribute (hStdError, OriginalConsoleColor);
     OriginalConsoleColor = -1;
 
-#else
-
-    fprintf (stderr, "\033[0m");
-
 #endif
 
 }
 
 static void set_console_color (int color) {
 
-#if     defined (_WIN32)
+#if     defined (unix) || defined (__unix) || defined (__unix__) || defined (__APPLE__)
+
+    fprintf (stderr, "\033[%dm", color);
+
+#elif   defined (_WIN32)
 
     HANDLE hStdError = GetStdHandle (STD_ERROR_HANDLE);
     WORD wColor;
@@ -56,10 +60,6 @@ static void set_console_color (int color) {
     wColor = (OriginalConsoleColor & 0xF0) + (color & 0xF);
     SetConsoleTextAttribute (hStdError, wColor);
 
-#else
-
-    fprintf (stderr, "\033[%dm", color);
-
 #endif
 
 }
diff --git a/unxz.c b/unxz.c
index db980d8270c4f5635dec1a044ed634d267aab177..86e6f53b2067e646b05a1790de2a2183d6a75b33 100755 (executable)
--- a/unxz.c
+++ b/unxz.c
@@ -78,6 +78,8 @@ int main (int argc, char **argv) {
         if (!(ifp = fopen (ipath, "r+b"))) {
         
             report_at (program_name, 0, REPORT_ERROR, "failed to open '%s' for reading", ipath);
+            
+            xz_dec_end (s);
             continue;
         
         }
@@ -88,7 +90,9 @@ int main (int argc, char **argv) {
             
                 report_at (program_name, 0, REPORT_ERROR, "skipping %s", ipath);
                 
+                xz_dec_end (s);
                 fclose (ifp);
+                
                 continue;
             
             }
@@ -102,7 +106,9 @@ int main (int argc, char **argv) {
             report_at (program_name, 0, REPORT_ERROR, "failed to open '%s' for writing", opath);
             free (opath);
             
+            xz_dec_end (s);
             fclose (ifp);
+            
             continue;
         
         }