Introduce and use gdb_file_up
[deliverable/binutils-gdb.git] / gdb / compile / compile.c
index 17716929ca702ad582aaf116c1edbde880b799aa..d8c505f8f129deae243a2da52010cf457a0dadd4 100644 (file)
@@ -547,14 +547,15 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
 
   compile_file_names fnames = get_new_file_names ();
 
-  src = gdb_fopen_cloexec (fnames.source_file (), "w");
-  if (src == NULL)
-    perror_with_name (_("Could not open source file for writing"));
-  inner_cleanup = make_cleanup (cleanup_unlink_file,
-                               (void *) fnames.source_file ());
-  if (fputs (code.c_str (), src) == EOF)
-    perror_with_name (_("Could not write to source file"));
-  fclose (src);
+  {
+    gdb_file_up src = gdb_fopen_cloexec (fnames.source_file (), "w");
+    if (src == NULL)
+      perror_with_name (_("Could not open source file for writing"));
+    inner_cleanup = make_cleanup (cleanup_unlink_file,
+                                 (void *) fnames.source_file ());
+    if (fputs (code.c_str (), src.get ()) == EOF)
+      perror_with_name (_("Could not write to source file"));
+  }
 
   if (compile_debug)
     fprintf_unfiltered (gdb_stdlog, "source file produced: %s\n\n",
This page took 0.024697 seconds and 4 git commands to generate.