bool mac_exist = false;
char *p_mac = NULL;
- p_mac = strdup(mac);
- if (p_mac == NULL) {
- ERR("strdup failed\n"); //LCOV_EXCL_LINE
- return TETHERING_ERROR_OUT_OF_MEMORY;
- }
-
fp = fopen(filepath, "a+");
if (!fp) {
ERR("fopen is failed\n"); //LCOV_EXCL_LINE
}
if (!mac_exist) {
+ p_mac = strdup(mac);
+ if (p_mac == NULL) {
+ ERR("strdup failed\n"); //LCOV_EXCL_LINE
+ fclose(fp);
+ return TETHERING_ERROR_OUT_OF_MEMORY;
+ }
+
fprintf(fp, "%s\n", mac);
if ((strcmp(filepath, ALLOWED_LIST) == 0))
allowed_list = g_slist_append(allowed_list, p_mac);
else if ((strcmp(filepath, BLOCKED_LIST) == 0))
blocked_list = g_slist_append(blocked_list, p_mac);
+ else
+ free(p_mac);
}
fclose(fp);