bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nohup output file v2


From: James Youngman
Subject: Re: nohup output file v2
Date: Sat, 28 Apr 2007 12:23:45 +0100

On 4/27/07, Noah Heusser <address@hidden> wrote:
+  char *file = "nohup.out";
[...]
+         case 'f':
+           file = strdup(optarg);
+           break;

Handling memory allocation in this way is a bit awkward.  What is one
supposed to do with "file" once one is finished with it?   If the -f
option was never given, file points at a fixed buffer which needs no
tidying up.  If the -f option was not given, file points at a buffer
which had been allocated via malloc().  So the cleanup code would have
to look like this:

if (f_option_had_been_given)
 free(file);

Instead of doing this and introducing the extra variable, it is
simpler to just do this:-

        case 'f':
          file = optarg;
          break;

Here, the string is not duplicated, file just points to the relevant
command-line argument.     Therefore it won't need to be free()d.
This approach works as long as nohup doesn't modify its own
command-line arguments.

A second option of course is not to worry about the memory leak, which
after all does not occur within a loop.  That's the approach you are
taking.  There's nothing wrong with that approach; nohup only
allocates the memory once so the impact of the leak is minimal.

James.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]