- free memory allocated by findbestmatchingname.

- use static buffer instead of "malloc and don't free"
  for dirname_of.
- fix indent.
This commit is contained in:
yamt 2002-06-09 11:56:59 +00:00
parent 9f3fed2b60
commit cc8d347c9a
5 changed files with 35 additions and 26 deletions

View File

@ -1,11 +1,11 @@
/* $NetBSD: main.c,v 1.23 2001/09/25 10:28:16 agc Exp $ */
/* $NetBSD: main.c,v 1.24 2002/06/09 11:56:59 yamt Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char *rcsid = "from FreeBSD Id: main.c,v 1.16 1997/10/08 07:45:43 charnier Exp";
#else
__RCSID("$NetBSD: main.c,v 1.23 2001/09/25 10:28:16 agc Exp $");
__RCSID("$NetBSD: main.c,v 1.24 2002/06/09 11:56:59 yamt Exp $");
#endif
#endif
@ -153,6 +153,7 @@ main(int argc, char **argv)
char tmp[FILENAME_MAX];
snprintf(tmp, sizeof(tmp), "%s/%s", dirname_of(*argv), s);
free(s);
if (Verbose)
printf("Using %s for %s\n", tmp, *argv);
@ -207,6 +208,7 @@ main(int argc, char **argv)
char tmp2[FILENAME_MAX];
snprintf(tmp2, sizeof(tmp2), "%s/%s", dirname_of(tmp), s);
free(s);
if (Verbose)
printf("Using %s for %s\n", tmp2, *argv);

View File

@ -1,11 +1,11 @@
/* $NetBSD: perform.c,v 1.63 2002/04/02 15:08:33 agc Exp $ */
/* $NetBSD: perform.c,v 1.64 2002/06/09 11:56:59 yamt Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.44 1997/10/13 15:03:46 jkh Exp";
#else
__RCSID("$NetBSD: perform.c,v 1.63 2002/04/02 15:08:33 agc Exp $");
__RCSID("$NetBSD: perform.c,v 1.64 2002/06/09 11:56:59 yamt Exp $");
#endif
#endif
@ -755,6 +755,7 @@ pkg_do(char *pkg)
char *t;
t = strrchr(contents, '/');
strcpy(t + 1, s);
free(s);
} else {
errx(1, "Where did our dependency go?!");
/* this shouldn't happen... X-) */

View File

@ -1,8 +1,8 @@
/* $NetBSD: main.c,v 1.24 2002/03/05 13:01:19 agc Exp $ */
/* $NetBSD: main.c,v 1.25 2002/06/09 11:57:00 yamt Exp $ */
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: main.c,v 1.24 2002/03/05 13:01:19 agc Exp $");
__RCSID("$NetBSD: main.c,v 1.25 2002/06/09 11:57:00 yamt Exp $");
#endif
/*
@ -471,8 +471,10 @@ main(int argc, char *argv[])
cwd = getcwd(NULL, 0);
p = findbestmatchingname(cwd, base);
if (p)
if (p) {
printf("%s/%s\n", cwd, p);
free(p);
}
free(cwd);
argv++;

View File

@ -1,11 +1,11 @@
/* $NetBSD: file.c,v 1.49 2002/06/09 03:50:13 yamt Exp $ */
/* $NetBSD: file.c,v 1.50 2002/06/09 11:57:00 yamt Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: file.c,v 1.29 1997/10/08 07:47:54 charnier Exp";
#else
__RCSID("$NetBSD: file.c,v 1.49 2002/06/09 03:50:13 yamt Exp $");
__RCSID("$NetBSD: file.c,v 1.50 2002/06/09 11:57:00 yamt Exp $");
#endif
#endif
@ -348,6 +348,7 @@ fileFindByPath(char *base, char *fname)
if (ispkgpattern(fname)) {
if ((cp = findbestmatchingname(".", fname)) != NULL) {
strcpy(tmp, cp);
free(cp);
return tmp;
}
} else {
@ -392,14 +393,16 @@ fileFindByPath(char *base, char *fname)
printf("'%s' expanded to '%s'\n", url, tmp);
return tmp; /* return expanded URL w/ corrent pkg */
} else {
cp = findbestmatchingname(dirname_of(tmp), basename_of(tmp));
if (cp) {
char *s;
s = strrchr(tmp, '/');
assert(s != NULL);
strcpy(s + 1, cp);
return tmp;
}
cp = findbestmatchingname(
dirname_of(tmp), basename_of(tmp));
if (cp) {
char *s;
s = strrchr(tmp, '/');
assert(s != NULL);
strcpy(s + 1, cp);
free(cp);
return tmp;
}
}
} else {
if (fexists(tmp)) {
@ -488,6 +491,7 @@ fileFindByPath(char *base, char *fname)
char *t;
t = strrchr(tmp, '/');
strcpy(t + 1, s);
free(s);
return tmp;
}
} else {
@ -515,6 +519,7 @@ fileFindByPath(char *base, char *fname)
strcpy(tmp, buf2); /* now we can overwrite it */
t = strrchr(tmp, '/');
strcpy(t+1, s);
free(s);
return tmp;
}
}

View File

@ -1,11 +1,11 @@
/* $NetBSD: str.c,v 1.35 2002/06/09 10:40:47 yamt Exp $ */
/* $NetBSD: str.c,v 1.36 2002/06/09 11:57:00 yamt Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "Id: str.c,v 1.5 1997/10/08 07:48:21 charnier Exp";
#else
__RCSID("$NetBSD: str.c,v 1.35 2002/06/09 10:40:47 yamt Exp $");
__RCSID("$NetBSD: str.c,v 1.36 2002/06/09 11:57:00 yamt Exp $");
#endif
#endif
@ -53,7 +53,7 @@ dirname_of(const char *path)
{
size_t cc;
char *s;
char *t;
static char buf[PATH_MAX];
if ((s = strrchr(path, '/')) == NULL) {
return ".";
@ -63,12 +63,11 @@ dirname_of(const char *path)
return "/";
}
cc = (size_t) (s - path);
if ((t = (char *) malloc(cc + 1)) == (char *) NULL) {
errx(1, "out of memory in dirname_of");
}
(void) memcpy(t, path, cc);
t[cc] = 0;
return t;
if (cc >= sizeof(buf))
errx(1, "dirname_of: too long dirname: '%s'", path);
(void) memcpy(buf, path, cc);
buf[cc] = 0;
return buf;
}
/*