Module Name: src
Committed By: christos
Date: Tue Jun 1 18:20:26 UTC 2010
Modified Files:
src/lib/libedit: filecomplete.c
Log Message:
tidy up memory allocation and don't unnecessarily print "./" before names.
To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/lib/libedit/filecomplete.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libedit/filecomplete.c
diff -u src/lib/libedit/filecomplete.c:1.18 src/lib/libedit/filecomplete.c:1.19
--- src/lib/libedit/filecomplete.c:1.18 Mon Jan 18 14:17:42 2010
+++ src/lib/libedit/filecomplete.c Tue Jun 1 14:20:26 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: filecomplete.c,v 1.18 2010/01/18 19:17:42 christos Exp $ */
+/* $NetBSD: filecomplete.c,v 1.19 2010/06/01 18:20:26 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: filecomplete.c,v 1.18 2010/01/18 19:17:42 christos Exp $");
+__RCSID("$NetBSD: filecomplete.c,v 1.19 2010/06/01 18:20:26 christos Exp $");
#endif /* not lint && not SCCSID */
#include <sys/types.h>
@@ -146,20 +146,24 @@
nptr = realloc(filename, strlen(temp) + 1);
if (nptr == NULL) {
free(filename);
+ filename = NULL;
return NULL;
}
filename = nptr;
(void)strcpy(filename, temp);
len = temp - text; /* including last slash */
+
nptr = realloc(dirname, len + 1);
if (nptr == NULL) {
- free(filename);
+ free(dirname);
+ dirname = NULL;
return NULL;
}
dirname = nptr;
(void)strncpy(dirname, text, len);
dirname[len] = '\0';
} else {
+ free(filename);
if (*text == 0)
filename = NULL;
else {
@@ -167,6 +171,7 @@
if (filename == NULL)
return NULL;
}
+ free(dirname);
dirname = NULL;
}
@@ -176,12 +181,14 @@
}
/* support for ``~user'' syntax */
- free(dirpath);
- if (dirname == NULL && (dirname = strdup("./")) == NULL)
- return NULL;
-
- if (*dirname == '~')
+ free(dirpath);
+ dirpath = NULL;
+ if (dirname == NULL) {
+ if ((dirname = strdup("")) == NULL)
+ return NULL;
+ dirpath = strdup("./");
+ } else if (*dirname == '~')
dirpath = fn_tilde_expand(dirname);
else
dirpath = strdup(dirname);