Commits

Pierre Joye  committed b34c4a2

no need to strdup path, max_path can be used, some safety around fontlist free

  • Participants
  • Parent commits dd33462

Comments (7)

  1. Remi Collet

    PHP ? ;)

    #if HAVE_LIMITS_H
    #include <limits.h>
    #endif
    
    #ifndef MAXPATHLEN
    # ifdef PATH_MAX
    #  define MAXPATHLEN PATH_MAX
    # elif defined(MAX_PATH)
    #  define MAXPATHLEN MAX_PATH
    # else
    #  define MAXPATHLEN 256    /* Should be safe for any weird systems that do not define it */
    # endif
    #endif
    

Files changed (1)

 	int font_found = 0;
 	char *fontsearchpath, *fontlist;
 	char *fullname = NULL;
-	char *name, *path, *dir;
+	char *name, *dir;
+	char path[MAX_PATH];
 	char *strtok_ptr = NULL;
 
 	/*
 		char *path_ptr = NULL;
 
 		/* make a fresh copy each time - strtok corrupts it. */
-		path = strdup (fontsearchpath);
+		sprintf (path, "%s", fontsearchpath);
 		/*
 		 * Allocate an oversized buffer that is guaranteed to be
 		 * big enough for all paths to be tested.
 		fullname = gdRealloc (fullname,
 		                      strlen (fontsearchpath) + strlen (name) + 8);
 		if (!fullname) {
-			free (path);
 			free (fontlist);
 			return "could not alloc full path of font";
 		}
 			sprintf (fullname, "%s", name);
 			if (access (fullname, R_OK) == 0) {
 				font_found++;
-				/* 2.0.16: memory leak fixed, Gustavo Scotti */
-				free (path);
 				break;
 			}
 		}
 				break;
 			}
 		}
-		free (path);
+
 		if (font_found)
 			break;
 	}
-	free (fontlist);
+	if (fontlist != NULL) {
+		free (fontlist);
+		fontlist = NULL;
+	}
 	if (!font_found) {
 		gdFree (fullname);
 		return "Could not find/open font";