Merge pull request #79 from darnir/free_string

Add new function psl_free_string()
This commit is contained in:
Tim Rühsen 2017-08-30 12:23:28 +02:00 committed by GitHub
commit 964e90a43e
5 changed files with 25 additions and 6 deletions

View File

@ -79,6 +79,10 @@ typedef struct _psl_ctx_st psl_ctx_t;
void
psl_free(psl_ctx_t *psl);
/* frees memory allocated by libpsl routines */
void
psl_free_string(char *str);
/* loads PSL data from file */
psl_ctx_t *
psl_load_file(const char *fname);

View File

@ -1613,6 +1613,21 @@ int psl_is_cookie_domain_acceptable(const psl_ctx_t *psl, const char *hostname,
return 0;
}
/**
* psl_free_string:
* @str: pointer to lowercase string returned by psl_str_to_utf8lower()
*
* This function free()'s the memory allocated by psl_str_to_utf8lower() when
* returning a lowercase string
*
* Since: 0.19
*/
void psl_free_string(char *str)
{
if (str)
free(str);
}
/**
* psl_str_to_utf8lower:
* @str: string to convert

View File

@ -133,16 +133,16 @@ static void test_psl(void)
char *lower = NULL;
psl_str_to_utf8lower("www.example.com", NULL, "de", &lower);
free(lower); lower = NULL;
psl_free_string(lower); lower = NULL;
psl_str_to_utf8lower("\374bel.de", NULL, "de", &lower);
free(lower); lower = NULL;
psl_free_string(lower); lower = NULL;
psl_str_to_utf8lower("\374bel.de", "iso-8859-1", NULL, &lower);
free(lower); lower = NULL;
psl_free_string(lower); lower = NULL;
psl_str_to_utf8lower(NULL, "utf-8", "en", &lower);
free(lower); lower = NULL;
psl_free_string(lower); lower = NULL;
}
psl_get_version();

View File

@ -81,7 +81,7 @@ static void testx(const psl_ctx_t *psl, const char *domain, const char *encoding
domain ? domain : "NULL", result ? result : "NULL", expected_result ? expected_result : "NULL");
}
free(lower);
psl_free_string(lower);
}
static void test(const psl_ctx_t *psl, const char *domain, const char *expected_result)

View File

@ -182,7 +182,7 @@ int main(int argc, const char *const *argv)
}
if (rc == PSL_SUCCESS)
free(lower);
psl_free_string(lower);
}
psl_free(psl);