diff --git a/dongle_infrastructure.c b/dongle_infrastructure.c index f25a1a8d040b8042953df56882928b722a88cb0a..43587d84b147c76a0ae3211b3f870b8a2adaf38c 100644 --- a/dongle_infrastructure.c +++ b/dongle_infrastructure.c @@ -16,7 +16,7 @@ #include "dongle_infrastructure.h" #include "dongle.h" -#include "dfs.h" +#include "stack.h" struct ubus_object *dongle_create_dynamic_object(struct device *dev_instance); @@ -219,6 +219,8 @@ char *get_device_name(char *dir_name) goto fail; } dr->path = strdup(dir_name); + if (dr->path) + goto fail_path; push(dr, &stack); while (!list_empty(&stack) && !name) { @@ -250,10 +252,15 @@ char *get_device_name(char *dir_name) sub_dr = malloc(sizeof(struct directory)); if (!sub_dr) { perror("malloc"); - goto fail_malloc; + continue; } sub_dr->path = strdup(path); + if (sub_dr->path) { + free(sub_dr); + continue; + } + push(sub_dr, &stack); continue; } @@ -271,6 +278,10 @@ char *get_device_name(char *dir_name) clear_list(&visited); clear_list(&stack); return name; +fail_path: + free(dr); +fail: + return NULL; } int get_devices(void) @@ -367,7 +378,7 @@ char *get_device_ip(char *device_name) break; addr.s_addr = strtoul(destination, NULL, IPV4_MAX); - inet_ntop(AF_INET, &addr.s_addr, ipv4_addr, IPV4_MAX); + inet_ntop(AF_INET, &(addr.s_addr), ipv4_addr, IPV4_MAX); printf("ipv4_addr %s\n", ipv4_addr); } @@ -376,6 +387,7 @@ char *get_device_ip(char *device_name) free(gateway); free(flags); fclose(fp); +fail: return ipv4_addr; } diff --git a/dongle_infrastructure.h b/dongle_infrastructure.h index 010716512a11015cb0756ac69343f06019bfa17f..8ff3bff0d15dedb8e3502de8e7d0a0f3f75c37e9 100644 --- a/dongle_infrastructure.h +++ b/dongle_infrastructure.h @@ -1,7 +1,9 @@ #ifndef INFRASTRUCTURE_H #define INFRASTRUCTURE_H #include "common.h" + #define IPV4_MAX 16 +#define DYNAMIC_OBJ_NAME_SIZE 50 struct USB { char *product; char *product_id; diff --git a/stack.c b/stack.c index d18efc2b4726ceee7a1e74272b53a38dd01b38b5..3116d1c04b43da8b4b508bbe046cf1bdc9496434 100644 --- a/stack.c +++ b/stack.c @@ -1,4 +1,4 @@ -#include "dfs.h" +#include "stack.h" void push(struct directory *dr, struct list_head *list) {