Skip to content

Commit

Permalink
free memory, redesign th eloop abit
Browse files Browse the repository at this point in the history
r16070
  • Loading branch information
joshk0 committed May 23, 2004
1 parent 16d806a commit c4d9f7d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
39 changes: 26 additions & 13 deletions netcfg-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void get_name(char *name, char *p)
return;
}

char** get_all_ifs (int all)
int get_all_ifs (int all, char*** ptr)
{
FILE *ifs = NULL;
char ibuf[512], rbuf[512];
Expand All @@ -159,7 +159,7 @@ char** get_all_ifs (int all)
fgets(ibuf, sizeof(ibuf), ifs); /* ditto */
}
else
return NULL;
return 0;

while (fgets(rbuf, sizeof(rbuf), ifs) != NULL)
{
Expand All @@ -181,7 +181,10 @@ char** get_all_ifs (int all)
list[len] = NULL;
}
fclose (ifs);
return list;

*ptr = list;

return len;
}

char *find_in_devnames(const char* iface)
Expand Down Expand Up @@ -314,9 +317,9 @@ void netcfg_die(struct debconfclient *client)
int netcfg_get_interface(struct debconfclient *client, char **interface,
int *numif)
{
char *inter, **ifs;
char *inter = NULL, **ifs;
size_t len;
int ret;
int ret, i;
int num_interfaces = 0;
char *ptr = NULL;
char *ifdsc = NULL;
Expand All @@ -332,31 +335,35 @@ int netcfg_get_interface(struct debconfclient *client, char **interface,
len = 128;
*ptr = '\0';

ifs = get_all_ifs(1);
num_interfaces = get_all_ifs(1, &ifs);

while (ifs && (inter = *ifs) != NULL) {
for (i = 0; i < num_interfaces; i++)
{
size_t newchars;

inter = ifs[i];

interface_down(inter);
ifdsc = get_ifdsc(client, inter);
newchars = strlen(inter) + strlen(ifdsc) + 5;
newchars = strlen(inter) + strlen(ifdsc) + 5; /* ": , " + NUL */
if (len < (strlen(ptr) + newchars)) {
if (!(ptr = realloc(ptr, len + newchars + 128)))
goto error;
len += newchars + 128;
}
di_snprintfcat(ptr, len, "%s: %s, ", inter, ifdsc);
num_interfaces++;
free(ifdsc);
ifs++;
}

if (num_interfaces == 0) {
if (num_interfaces == 0)
{
debconf_input(client, "high", "netcfg/no_interfaces");
debconf_go(client);
free(ptr);
exit(1);
} else if (num_interfaces > 1) {
}
else if (num_interfaces > 1)
{
*numif = num_interfaces;
/* remove the trailing ", ", which confuses cdebconf */
ptr[strlen(ptr) - 2] = '\0';
Expand All @@ -377,7 +384,9 @@ int netcfg_get_interface(struct debconfclient *client, char **interface,
return ret;
if (!inter)
netcfg_die(client);
} else if (num_interfaces == 1) {
}
else if (num_interfaces == 1)
{
inter = ptr;
*numif = 1;
}
Expand All @@ -391,6 +400,10 @@ int netcfg_get_interface(struct debconfclient *client, char **interface,

*interface = strdup(*interface);

/* Free allocated memory */
while (ifs && *ifs)
free(*ifs++);

return 0;

error:
Expand Down
4 changes: 1 addition & 3 deletions netcfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extern int is_interface_up (char *inter);

extern void get_name (char *name, char *p);

extern char** get_all_ifs (int all);
extern int get_all_ifs (int all, char ***ptr);

extern char *get_ifdsc (struct debconfclient *client, const char *ifp);

Expand Down Expand Up @@ -97,8 +97,6 @@ extern int netcfg_wireless_set_wep (struct debconfclient *client, char* iface);
extern int iface_is_hotpluggable(const char *iface);
extern void deconfigure_network(void);

extern method_t mii_diag_status_lite (char *ifname);

extern void interface_up (char*);
extern void interface_down (char*);

Expand Down

0 comments on commit c4d9f7d

Please sign in to comment.