summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorjoerg <joerg@FreeBSD.org>1996-12-14 19:53:49 +0000
committerjoerg <joerg@FreeBSD.org>1996-12-14 19:53:49 +0000
commit5476bdc6871cd231f6041ffed18201a40fd63370 (patch)
tree5f4ce179ffc745f34801c743beca866f4dff0bf6 /usr.sbin
parent000a733206a490453542c9e437941673ec57912a (diff)
downloadFreeBSD-src-5476bdc6871cd231f6041ffed18201a40fd63370.zip
FreeBSD-src-5476bdc6871cd231f6041ffed18201a40fd63370.tar.gz
Part #2 of the config cleanup. More aggressive, replaced an NIH
version of strdup() by a macro, killed many calls to strdup(), thus potentially wasting less malloc'ed space (their args were never be free()ed desptie despite of being malloc'ed). Probably still a huge memory leak at all... Also killed two totally useless variables. I've tested it as i could, but wouldn't be surprised if unexpected problems showed up. So watch out this space!
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/config/config.y48
-rw-r--r--usr.sbin/config/mkheaders.c5
-rw-r--r--usr.sbin/config/mkmakefile.c3
-rw-r--r--usr.sbin/config/mkoptions.c10
-rw-r--r--usr.sbin/config/mkswapconf.c3
5 files changed, 31 insertions, 38 deletions
diff --git a/usr.sbin/config/config.y b/usr.sbin/config/config.y
index 91fbf24..c35127c 100644
--- a/usr.sbin/config/config.y
+++ b/usr.sbin/config/config.y
@@ -125,8 +125,8 @@
struct device cur;
struct device *curp = 0;
-char *temp_id;
-char *val_id;
+
+#define ns(s) strdup(s)
%}
%%
@@ -188,17 +188,16 @@ Config_spec:
struct cputype *cp =
(struct cputype *)malloc(sizeof (struct cputype));
memset(cp, 0, sizeof(*cp));
- cp->cpu_name = ns($2);
+ cp->cpu_name = $2;
cp->cpu_next = cputype;
cputype = cp;
- free(temp_id);
} |
OPTIONS Opt_list
|
MAKEOPTIONS Mkopt_list
|
IDENT ID
- = { ident = ns($2); } |
+ = { ident = $2; } |
System_spec
|
MAXUSERS NUMBER
@@ -397,7 +396,7 @@ Option:
struct opt *op = (struct opt *)malloc(sizeof (struct opt));
char *s;
memset(op, 0, sizeof(*op));
- op->op_name = ns($1);
+ op->op_name = $1;
op->op_next = opt;
op->op_value = 0;
opt = op;
@@ -406,34 +405,31 @@ Option:
*s = '\0';
op->op_value = ns(s + 1);
}
- free(temp_id);
} |
Save_id EQUALS Opt_value
= {
struct opt *op = (struct opt *)malloc(sizeof (struct opt));
memset(op, 0, sizeof(*op));
- op->op_name = ns($1);
+ op->op_name = $1;
op->op_next = opt;
- op->op_value = ns($3);
+ op->op_value = $3;
opt = op;
- free(temp_id);
- free(val_id);
} ;
Opt_value:
ID
- = { $$ = val_id = ns($1); } |
+ = { $$ = $1; } |
NUMBER
= {
char nb[16];
(void) sprintf(nb, "%d", $1);
- $$ = val_id = ns(nb);
+ $$ = ns(nb);
} ;
Save_id:
ID
- = { $$ = temp_id = ns($1); }
+ = { $$ = $1; }
;
Mkopt_list:
@@ -447,18 +443,16 @@ Mkoption:
= {
struct opt *op = (struct opt *)malloc(sizeof (struct opt));
memset(op, 0, sizeof(*op));
- op->op_name = ns($1);
+ op->op_name = $1;
op->op_ownfile = 0; /* for now */
op->op_next = mkopt;
- op->op_value = ns($3);
+ op->op_value = $3;
mkopt = op;
- free(temp_id);
- free(val_id);
} ;
Dev:
ID
- = { $$ = ns($1); }
+ = { $$ = $1; }
;
Device_spec:
@@ -620,7 +614,7 @@ Info:
IOSIZ NUMBER
= { cur.d_msize = $2; } |
PORT device_name
- = { cur.d_port = ns($2); } |
+ = { cur.d_port = $2; } |
PORT NUMBER
= { cur.d_portn = $2; } |
PORT AUTO
@@ -672,20 +666,6 @@ yyerror(s)
}
/*
- * return the passed string in a new space
- */
-char *
-ns(str)
- register char *str;
-{
- register char *cp;
-
- cp = malloc((unsigned)(strlen(str)+1));
- (void) strcpy(cp, str);
- return (cp);
-}
-
-/*
* add a device to the list of devices
*/
newdev(dp)
diff --git a/usr.sbin/config/mkheaders.c b/usr.sbin/config/mkheaders.c
index bfa5692..735658d 100644
--- a/usr.sbin/config/mkheaders.c
+++ b/usr.sbin/config/mkheaders.c
@@ -40,10 +40,13 @@ static char sccsid[] = "@(#)mkheaders.c 8.1 (Berkeley) 6/6/93";
*/
#include <stdio.h>
+#include <string.h>
#include <ctype.h>
#include "config.h"
#include "y.tab.h"
+#define ns(s) strdup(s)
+
headers()
{
register struct file_list *fl;
@@ -157,7 +160,7 @@ do_header(dev, hname, count)
if (oldcount == -1) {
fl = (struct file_list *) malloc(sizeof *fl);
bzero(fl, sizeof(*fl));
- fl->f_fn = ns(name); /* malloced */
+ fl->f_fn = ns(name);
fl->f_type = count;
fl->f_next = fl_head;
fl_head = fl;
diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c
index 513a503..56aa44a 100644
--- a/usr.sbin/config/mkmakefile.c
+++ b/usr.sbin/config/mkmakefile.c
@@ -42,6 +42,7 @@ static char sccsid[] = "@(#)mkmakefile.c 8.1 (Berkeley) 6/6/93";
*/
#include <stdio.h>
+#include <string.h>
#include <ctype.h>
#include "y.tab.h"
#include "config.h"
@@ -61,6 +62,8 @@ static char sccsid[] = "@(#)mkmakefile.c 8.1 (Berkeley) 6/6/93";
wd = word; \
}
+#define ns(s) strdup(s)
+
static struct file_list *fcur;
char *tail();
extern int old_config_present;
diff --git a/usr.sbin/config/mkoptions.c b/usr.sbin/config/mkoptions.c
index 40fe87e..aea47b6 100644
--- a/usr.sbin/config/mkoptions.c
+++ b/usr.sbin/config/mkoptions.c
@@ -41,10 +41,15 @@ static char sccsid[] = "@(#)mkheaders.c 8.1 (Berkeley) 6/6/93";
*/
#include <stdio.h>
+#include <string.h>
#include <ctype.h>
#include "config.h"
#include "y.tab.h"
+#define ns(s) strdup(s)
+
+static char *lower __P((char *));
+
options()
{
struct opt_list *ol;
@@ -57,7 +62,7 @@ options()
for (cp = cputype; cp; cp = cp->cpu_next) {
struct opt *op = (struct opt *)malloc(sizeof (struct opt));
memset(op, 0, sizeof(*op));
- op->op_name = cp->cpu_name;
+ op->op_name = ns(cp->cpu_name);
op->op_value = 0;
op->op_next = opt;
opt = op;
@@ -226,7 +231,6 @@ read_options()
struct opt_list *po;
int first = 1;
char genopt[80];
- char *lower();
otab = 0;
(void) snprintf(fname, sizeof fname, "../../conf/options");
@@ -298,7 +302,7 @@ next:
goto next;
}
-char *
+static char *
lower(str)
register char *str;
{
diff --git a/usr.sbin/config/mkswapconf.c b/usr.sbin/config/mkswapconf.c
index 1d5756f..18a8084 100644
--- a/usr.sbin/config/mkswapconf.c
+++ b/usr.sbin/config/mkswapconf.c
@@ -45,6 +45,9 @@ static char sccsid[] = "@(#)mkswapconf.c 8.1 (Berkeley) 6/6/93";
#include <ctype.h>
#include <stdio.h>
+#include <string.h>
+
+#define ns(s) strdup(s)
swapconf()
{
OpenPOWER on IntegriCloud