Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libedit tidy up memory allocation and don't unnecessaril...
details: https://anonhg.NetBSD.org/src/rev/53cd3a1429b1
branches: trunk
changeset: 755325:53cd3a1429b1
user: christos <christos%NetBSD.org@localhost>
date: Tue Jun 01 18:20:26 2010 +0000
description:
tidy up memory allocation and don't unnecessarily print "./" before names.
diffstat:
lib/libedit/filecomplete.c | 23 +++++++++++++++--------
1 files changed, 15 insertions(+), 8 deletions(-)
diffs (72 lines):
diff -r 7d03dc079f06 -r 53cd3a1429b1 lib/libedit/filecomplete.c
--- a/lib/libedit/filecomplete.c Tue Jun 01 18:00:28 2010 +0000
+++ b/lib/libedit/filecomplete.c Tue Jun 01 18:20:26 2010 +0000
@@ -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 == '~')
+ 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);
Home |
Main Index |
Thread Index |
Old Index