diff mbox

[libcpp] Free some variables

Message ID 506C8EBD.1070204@net-b.de
State New
Headers show

Commit Message

Tobias Burnus Oct. 3, 2012, 7:15 p.m. UTC
Build on x86-64-linux with C/C++/Fortran. I will now do an all-language 
build/regtest.
OK when it passes?

Tobias

Comments

Tom Tromey Oct. 15, 2012, 5:17 p.m. UTC | #1
>>>>> "Tobias" == Tobias Burnus <burnus@net-b.de> writes:

Tobias> Build on x86-64-linux with C/C++/Fortran. I will now do an
Tobias> all-language build/regtest.
Tobias> OK when it passes?

Tobias> 2012-10-03  Tobias Burnus  <burnus@net-b.de>

Tobias> 	* files.c (read_file_guts, _cpp_save_file_entries): Free memory
Tobias> 	before returning.
Tobias> 	* lex.c (warn_about_normalization): Ditto.
Tobias> 	* mkdeps.c (deps_save): Ditto.
Tobias> 	* pch.c (cpp_valid_state): Ditto.

This is ok.  Thanks.

Tom
diff mbox

Patch

2012-10-03  Tobias Burnus  <burnus@net-b.de>

	* files.c (read_file_guts, _cpp_save_file_entries): Free memory
	before returning.
	* lex.c (warn_about_normalization): Ditto.
	* mkdeps.c (deps_save): Ditto.
	* pch.c (cpp_valid_state): Ditto.

diff --git a/libcpp/files.c b/libcpp/files.c
index 5b3a37b..6fc24e2 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -668,12 +668,13 @@  read_file_guts (cpp_reader *pfile, _cpp_file *file)
 	}
     }
 
   if (count < 0)
     {
       cpp_errno (pfile, CPP_DL_ERROR, file->path);
+      free (buf);
       return false;
     }
 
   if (regular && total != size && STAT_SIZE_RELIABLE (file->st))
     cpp_error (pfile, CPP_DL_WARNING,
 	       "%s is shorter than expected", file->path);
@@ -1756,12 +1757,13 @@  _cpp_save_file_entries (cpp_reader *pfile, FILE *fp)
 	  FILE *ff;
 	  int oldfd = f->fd;
 
 	  if (!open_file (f))
 	    {
 	      open_file_failed (pfile, f, 0);
+	      free (result);
 	      return false;
 	    }
 	  ff = fdopen (f->fd, "rb");
 	  md5_stream (ff, result->entries[count].sum);
 	  fclose (ff);
 	  f->fd = oldfd;
diff --git a/libcpp/lex.c b/libcpp/lex.c
index ab904db..23809bc 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -1091,12 +1091,13 @@  warn_about_normalization (cpp_reader *pfile,
       if (NORMALIZE_STATE_RESULT (s) == normalized_C)
 	cpp_warning_with_line (pfile, CPP_W_NORMALIZE, token->src_loc, 0,
 			       "`%.*s' is not in NFKC", (int) sz, buf);
       else
 	cpp_warning_with_line (pfile, CPP_W_NORMALIZE, token->src_loc, 0,
 			       "`%.*s' is not in NFC", (int) sz, buf);
+      free (buf);
     }
 }
 
 /* Returns TRUE if the sequence starting at buffer->cur is invalid in
    an identifier.  FIRST is TRUE if this starts an identifier.  */
 static bool
diff --git a/libcpp/mkdeps.c b/libcpp/mkdeps.c
index af11ac3..b576813 100644
--- a/libcpp/mkdeps.c
+++ b/libcpp/mkdeps.c
@@ -396,31 +396,39 @@  deps_save (struct deps *deps, FILE *f)
 int
 deps_restore (struct deps *deps, FILE *fd, const char *self)
 {
   unsigned int i, count;
   size_t num_to_read;
   size_t buf_size = 512;
-  char *buf = XNEWVEC (char, buf_size);
+  char *buf;
 
   /* Number of dependences.  */
   if (fread (&count, 1, sizeof (count), fd) != sizeof (count))
     return -1;
 
+  buf = XNEWVEC (char, buf_size);
+
   /* The length of each dependence string, followed by the string.  */
   for (i = 0; i < count; i++)
     {
       /* Read in # bytes in string.  */
       if (fread (&num_to_read, 1, sizeof (size_t), fd) != sizeof (size_t))
-	return -1;
+	{
+	  free (buf);
+	  return -1;
+	}
       if (buf_size < num_to_read + 1)
 	{
 	  buf_size = num_to_read + 1 + 127;
 	  buf = XRESIZEVEC (char, buf, buf_size);
 	}
       if (fread (buf, 1, num_to_read, fd) != num_to_read)
-	return -1;
+	{
+	  free (buf);
+	  return -1;
+	}
       buf[num_to_read] = '\0';
 
       /* Generate makefile dependencies from .pch if -nopch-deps.  */
       if (self != NULL && filename_cmp (buf, self) != 0)
         deps_add_dep (deps, buf);
     }
diff --git a/libcpp/pch.c b/libcpp/pch.c
index d278f14..001bf3f 100644
--- a/libcpp/pch.c
+++ b/libcpp/pch.c
@@ -707,13 +707,12 @@  cpp_valid_state (cpp_reader *r, const char *name, int fd)
 
   /* We win!  */
   return 0;
 
  error:
   cpp_errno (r, CPP_DL_ERROR, "while reading precompiled header");
-  return -1;
 
  fail:
   free (namebuf);
   free (undeftab);
   free (nl.defs);
   return 1;