changeset 1463:bdd42c1463f8 draft

Add error test and fix memory leak, reported by Ashwini Sharma.
author Rob Landley <rob@landley.net>
date Mon, 08 Sep 2014 08:26:02 -0500
parents 83cbfc4b0de7
children 836ff051a071
files toys/posix/find.c
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/toys/posix/find.c	Sun Sep 07 19:33:18 2014 -0500
+++ b/toys/posix/find.c	Mon Sep 08 08:26:02 2014 -0500
@@ -315,11 +315,11 @@
         }
       } else if (!strcmp(s, "type")) {
         if (check) {
-          char c = stridx("bcdlpfs", *ss[1]);
           int types[] = {S_IFBLK, S_IFCHR, S_IFDIR, S_IFLNK, S_IFIFO,
-                         S_IFREG, S_IFSOCK};
+                         S_IFREG, S_IFSOCK}, i = stridx("bcdlpfs", *ss[1]);
 
-          if ((new->st.st_mode & S_IFMT) != types[c]) test = 0;
+          if (i<0) error_exit("bad -type '%c'", *ss[1]);
+          if ((new->st.st_mode & S_IFMT) != types[i]) test = 0;
         }
 
       } else if (!strcmp(s, "atime")) {
@@ -447,7 +447,12 @@
 
           if (*s == 'o') {
             char *prompt = xmprintf("[%s] %s", ss1, name);
-            if(!(test = yesno(prompt, 0))) goto cont;
+            test = yesno(prompt, 0);
+            free(prompt);
+            if (!test) {
+              free(name);
+              goto cont;
+            }
           }
 
           // Add next name to list (global list without -dir, local with)