[PATCH] io/fts.c: Remove redundant checks

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] io/fts.c: Remove redundant checks

Dmitry V. Levin
2006-10-02  Dmitry V. Levin  <[hidden email]>

        * io/fts.c (fts_close, fts_build, fts_palloc): Remove redundant
        checks.

--- glibc-2.5.orig/io/fts.c
+++ glibc-2.5/io/fts.c
@@ -251,8 +251,7 @@ fts_close(sp)
  /* Free up child linked list, sort array, path buffer. */
  if (sp->fts_child)
  fts_lfree(sp->fts_child);
- if (sp->fts_array)
- free(sp->fts_array);
+ free(sp->fts_array);
  free(sp->fts_path);
 
  /* Return to original directory, save errno if necessary. */
@@ -705,8 +704,7 @@ fts_build(sp, type)
  * structures already allocated.
  */
 mem1: saved_errno = errno;
- if (p)
- free(p);
+ free(p);
  fts_lfree(head);
  (void)__closedir(dirp);
  cur->fts_info = FTS_ERR;
@@ -1043,10 +1041,7 @@ fts_palloc(sp, more)
  * We limit fts_pathlen to USHRT_MAX to be safe in both cases.
  */
  if (sp->fts_pathlen < 0 || sp->fts_pathlen >= USHRT_MAX) {
- if (sp->fts_path) {
- free(sp->fts_path);
- sp->fts_path = NULL;
- }
+ free(sp->fts_path);
  sp->fts_path = NULL;
  __set_errno (ENAMETOOLONG);
  return (1);

--
ldv

attachment0 (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] io/fts.c: Remove redundant checks

Ulrich Drepper
Applied.

--
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖


signature.asc (259 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] io/fts.c: Remove redundant checks

Jim Meyering
In reply to this post by Dmitry V. Levin
"Dmitry V. Levin" <[hidden email]> wrote:
> 2006-10-02  Dmitry V. Levin  <[hidden email]>
>
> * io/fts.c (fts_close, fts_build, fts_palloc): Remove redundant
> checks.

Thank you.
I've applied those changes to the version of fts.c in gnulib, too.
If you have applications that use fts and that can tolerate
a different ABI, you should consider using the gnulib version:
it has fewer limitations, and is thread-safe and more efficient.

> --- glibc-2.5.orig/io/fts.c
> +++ glibc-2.5/io/fts.c
> @@ -251,8 +251,7 @@ fts_close(sp)
>   /* Free up child linked list, sort array, path buffer. */
>   if (sp->fts_child)
>   fts_lfree(sp->fts_child);
> - if (sp->fts_array)
> - free(sp->fts_array);
> + free(sp->fts_array);
>   free(sp->fts_path);
>
>   /* Return to original directory, save errno if necessary. */
> @@ -705,8 +704,7 @@ fts_build(sp, type)
>   * structures already allocated.
>   */
>  mem1: saved_errno = errno;
> - if (p)
> - free(p);
> + free(p);
>   fts_lfree(head);
>   (void)__closedir(dirp);
>   cur->fts_info = FTS_ERR;
> @@ -1043,10 +1041,7 @@ fts_palloc(sp, more)
>   * We limit fts_pathlen to USHRT_MAX to be safe in both cases.
>   */
>   if (sp->fts_pathlen < 0 || sp->fts_pathlen >= USHRT_MAX) {
> - if (sp->fts_path) {
> - free(sp->fts_path);
> - sp->fts_path = NULL;
> - }
> + free(sp->fts_path);
>   sp->fts_path = NULL;
>   __set_errno (ENAMETOOLONG);
>   return (1);
>
> --
> ldv