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!
This commit is contained in:
joerg 1996-12-14 19:53:49 +00:00
parent e75a5fb5a3
commit 611928750f
5 changed files with 31 additions and 38 deletions

View File

@ -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
@ -671,20 +665,6 @@ yyerror(s)
fprintf(stderr, "config: line %d: %s\n", yyline + 1, 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
*/

View File

@ -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;

View File

@ -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;

View File

@ -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 @@ read_options()
goto next;
}
char *
static char *
lower(str)
register char *str;
{

View File

@ -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()
{