last: fix memory leak
Subsystems (2)
PATCH 1/4 last: fix memory leak
--- login-utils/last.c | 4 ++++ 1 file changed, 4 insertions(+)
login-utils/last.c +4 -0
@@ -819,6 +819,10 @@ static void process_wtmp_file(const struct last_control *ctl)printf (_ ("\n%s begins %s" ),basename (ctl->altv[ctl->alti]),ctime (&begintime));fclose (fp); +for (p = utmplist; p; p = next) { + next = p->next; +free (p); + } }int main (int argc,char **argv)
Signature · 1 line
1.8.4
PATCH 2/4 tools: generate autotools files if missing
--- tools/config-gen | 4 ++++ 1 file changed, 4 insertions(+)
tools/config-gen +4 -0
@@ -28,5 +28,9 @@ if [ -n "$CFLAGS" ]; then export CFLAGS fi +if [ ! -f ./configure ]; then + ./autogen.sh +fi + echo ./configure $opts
Signature · 1 line
1.8.4
Re: [PATCH 2/4] tools: generate autotools files if missing
Quoted 4 lines · Sami Kerola
Signed-off-by Sami Kerola <[email protected]>--- tools/config-gen | 4 ++++ 1 file changed, 4 insertions(+)
Applied, thanks.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
PATCH 3/4 lib/fileutils: advice there is no point caching temporary files
In reply to Sami Kerola--- lib/fileutils.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/fileutils.c +4 -0
@@ -8,6 +8,7 @@#include <unistd.h> #include <sys/time.h> #include <sys/resource.h> +#include <fcntl.h> #include "c.h" #include "fileutils.h"
@@ -43,6 +44,9 @@ int xmkstemp(char **tmpname, char *dir)free (localtmp); localtmp =NULL ; } +#ifdef POSIX_FADV_NOREUSE +posix_fadvise (fd,0 ,lseek (fd,0 ,0 ),POSIX_FADV_NOREUSE ); +#endif *tmpname = localtmp;return fd; }
Signature · 1 line
1.8.4
Re: [PATCH 3/4] lib/fileutils: advice there is no point caching temporary files
Quoted 19 lines · Sami Kerola
Signed-off-by Sami Kerola <[email protected]>--- lib/fileutils.c | 4 ++++ 1 file changed, 4 insertions(+)lib/fileutils.c +1
-0@@ -8,6 +8,7 @@#include <unistd.h> #include <sys/time.h> #include <sys/resource.h> +#include <fcntl.h> #include "c.h" #include "fileutils.h"
lib/fileutils.c int xmkstemp(char **tmpname, char *dir) · line 52
Quoted 9 lines
lib/fileutils.c +3
-0@@ -43,6 +44,9 @@ int xmkstemp(char **tmpname, char *dir)free (localtmp); localtmp =NULL ; } +#ifdef POSIX_FADV_NOREUSE +posix_fadvise (fd,0 ,lseek (fd,0 ,0 ),POSIX_FADV_NOREUSE ); +#endif *tmpname = localtmp;return fd; }
I don't follow. The above is saying to NOREUSE the data from the start to the current position?
But won't the file be empty and the current position == 0 here? Also POSIX_FADV_NOREUSE currently does nothing in the kernel. There is POSIX_FADV_DONTNEED to drop the file (range) from cache. But I'm not sure that's appropriate or needed for all temp files? Note also DONTNEED is auto done when a file is unlinked.
cheers,
Pádraig.
Re: [PATCH 3/4] lib/fileutils: advice there is no point caching temporary files
Quoted 12 lines · Pádraig Brady
lib/fileutils.c int xmkstemp(char **tmpname, char *dir) · line 49
Quoted 3 lines · Sami Kerola
lib/fileutils.c +3
-0+#ifdef POSIX_FADV_NOREUSE +posix_fadvise (fd,0 ,lseek (fd,0 ,0 ),POSIX_FADV_NOREUSE ); +#endif I don't follow. The above is saying to NOREUSE the data from the start to the current position?
But won't the file be empty and the current position == 0 here? AlsoPOSIX_FADV_NOREUSEcurrently does nothing in the kernel. There isPOSIX_FADV_DONTNEEDto drop the file (range) from cache. But I'm not sure that's appropriate or needed for all temp files? Note also DONTNEED is auto done when a file is unlinked.
Hi Pádraig,
I misunderstood posix_fadvice() manual page. Thank you for explaining how caching instructions work. Perhaps adding a note to posix_fadvise(3P) about unlinking and DONOTNEED would be appropriate. That, after all, makes manual fiddling with this function pointless in cases like I proposed.
Signature · 2 lines
Sami Kerola http://www.iki.fi/kerolasa/
PATCH 4/4 hexdump: revert global exitval variable change
In reply to Sami KerolaThe change f2a037fb7b153954d5d34cca48182b6d8832fcfa had unfavorable effect of making hexdump to return non-zero exit value always.
This happen because oversight when 'exitval' gets to be set. By clance, one might expect main() to call next() which will return value for 'exitval'. That assessment misses later call chain main() -> display() -> get() -> next(), which in reverse should return correct value for 'exitval'.
It was mentioned in util-linux maillist that Ondrej Oprala is working on major renewal of the hexdump . That in mind it seems best to simply to revert the global 'exitval' and avoid conflict with Ondrej's work.
Reference: http://markmail.org/message/sbnvuhkboreujj5p
--- text-utils/display.c | 6 +++--- text-utils/hexdump.c | 4 ++-- text-utils/hexdump.h | 1 + 3 files changed, 6 insertions(+), 5 deletions(-)
text-utils/display.c +3 -3
@@ -295,7 +295,7 @@ get(void)int next (char **argv) {static int done; -int statok, exitval =0 ; +int statok;if (argv) { _argv = argv;
@@ -305,14 +305,14 @@ int next(char **argv)if (*_argv) {if (!(freopen (*_argv,"r" , stdin))) {warn ("%s" , *_argv); - exitval =1 ; + exitval =EXIT_FAILURE ; ++_argv;continue ; } statok = done =1 ; }else {if (done++) -return (exitval); +return (0 ); statok =0 ; }if (skip)
text-utils/hexdump.c +2 -2
@@ -47,11 +47,11 @@FS *fshead;/* head of format strings */ ssize_t blocksize;/* data block size */ +int exitval;/* final exit value */ ssize_t length =-1 ;/* max bytes to read */ int main (int argc,char **argv) { -int exitval;/* final exit value */ FS *tfs;char *p;
@@ -76,7 +76,7 @@ int main(int argc, char **argv)for (tfs = fshead; tfs; tfs = tfs->nextfs)rewrite (tfs); - exitval =next (argv); + (void )next (argv);display ();return exitval; }
text-utils/hexdump.h +1 -0
@@ -73,6 +73,7 @@ typedef struct _fs { /* format strings */extern FU *endfu;extern FS *fshead;/* head of format strings list */ extern ssize_t blocksize;/* data block size */ +extern int exitval;/* final exit value */ extern ssize_t length;/* max bytes to read */ extern off_t skip;/* bytes to skip */
Signature · 1 line
1.8.4
Re: [PATCH 4/4] hexdump: revert global exitval variable change
Quoted 4 lines · Sami Kerola
text-utils/display.c | 6 +++--- text-utils/hexdump.c | 4 ++-- text-utils/hexdump.h | 1 + 3 files changed, 6 insertions(+), 5 deletions(-)
Applied, thanks.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Quoted 4 lines · Sami Kerola
Signed-off-by Sami Kerola <[email protected]>--- login-utils/last.c | 4 ++++ 1 file changed, 4 insertions(+)
Applied, thanks.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com