bug-tar
[Top][All Lists]
Advanced

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

Re: [Bug-tar] [PATCH] tar: simplify code in system.c


From: Sergey Poznyakoff
Subject: Re: [Bug-tar] [PATCH] tar: simplify code in system.c
Date: Wed, 20 Feb 2013 16:28:45 +0300

Pavel Raiskup <address@hidden> ha escrit:

> Move the xexec function into #ifndef MSDOS part of file.

Yes, that's reasonable.

> * system.c (try_exec): New function - modified previous xexec.

This will cause a memory leak and imply unnecessary memory
reallocations.

What happens here is:

487      if (wordsplit (p, &ws, wsflags))
488        FATAL_ERROR ((0, 0, _("cannot split string '%s': %s"),
489                      p, wordsplit_strerror (&ws)));
490      wsflags |= WRDSF_REUSE;

after the first call to wordsplit the WRDSF_REUSE flag is set, which
forces wordsplit to reuse already allocated memory on the next iteration
of the loop.

If using the proposed try_exec, then (1) the memory allocated by each
call to wordsplit is never freed, (2) an extra call to xmalloc causes
unnecessary memory allocation, which is never freed as well, and (3)
each subsequent call to wordsplit allocates new blocks of memory instead
of reusing the previously allocated ones. Besides, shifting a memory
array and adding an extra element is much faster than allocating a new
block of memory for the sole purpose of tucking an extra "-d" in it.

Regards,
Sergey



reply via email to

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