Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clib-package.c memory leaks #210

Merged
merged 5 commits into from Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/common/clib-package.c
Expand Up @@ -657,6 +657,10 @@ clib_package_new_from_slug_with_package_name(const char *slug, int verbose,
#ifdef HAVE_PTHREADS
init_curl_share();
_debug("GET %s", json_url);
if (res) {
// clean up when retrying
http_get_free(res);
}
Isty001 marked this conversation as resolved.
Show resolved Hide resolved
res = http_get_shared(json_url, clib_package_curl_share);
#else
res = http_get(json_url);
Expand Down Expand Up @@ -1380,7 +1384,9 @@ int clib_package_install(clib_package_t *pkg, const char *dir, int verbose) {
#ifdef HAVE_PTHREADS
pthread_mutex_lock(&lock.mutex);
#endif
hash_set(visited_packages, strdup(pkg->name), "t");
if (!hash_has(visited_packages, pkg->name)) {
hash_set(visited_packages, strdup(pkg->name), "t");
}
#ifdef HAVE_PTHREADS
pthread_mutex_unlock(&lock.mutex);
#endif
Expand All @@ -1398,9 +1404,9 @@ int clib_package_install(clib_package_t *pkg, const char *dir, int verbose) {
#ifdef HAVE_PTHREADS
if (0 != fetch) {
fetch_package_file_thread_data_t *data = fetch;
int *status = 0;
pthread_join(data->thread, (void **)&status);
if (0 != status) {
int *status;
pthread_join(data->thread, (void **) &status);
if (NULL != status) {
rc = *status;
free(status);
status = 0;
Expand Down Expand Up @@ -1488,14 +1494,14 @@ int clib_package_install(clib_package_t *pkg, const char *dir, int verbose) {
} else {
while (--i >= 0) {
fetch_package_file_thread_data_t *data = fetchs[i];
int *status = 0;
pthread_join(data->thread, (void **)status);
int *status;
pthread_join(data->thread, (void **) &status);
free(data);
fetchs[i] = NULL;

(void)pending--;

if (0 != status) {
if (NULL != status) {
rc = *status;
free(status);
status = 0;
Expand All @@ -1517,15 +1523,15 @@ int clib_package_install(clib_package_t *pkg, const char *dir, int verbose) {
#ifdef HAVE_PTHREADS
while (--i >= 0) {
fetch_package_file_thread_data_t *data = fetchs[i];
int *status = 0;
int *status;

pthread_join(data->thread, (void **)status);
pthread_join(data->thread, (void **) &status);

(void)pending--;
free(data);
fetchs[i] = NULL;

if (0 != status) {
if (NULL != status) {
rc = *status;
free(status);
status = 0;
Expand Down Expand Up @@ -1696,4 +1702,6 @@ void clib_package_cleanup() {
hash_free(visited_packages);
visited_packages = 0;
}

curl_share_cleanup(clib_package_curl_share);
}
2 changes: 1 addition & 1 deletion test/cache/cache-test.c
Expand Up @@ -77,7 +77,7 @@ main() {
it("should manage the search cache") {
char *cached_search;

clib_cache_delete_search();
clib_cache_delete_search();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah whoops, #209 should have formatted tests too. I forgot we have .c tests now :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#211 :)


assert_equal(0, clib_cache_has_search());
assert_null(clib_cache_read_search());
Expand Down
3 changes: 3 additions & 0 deletions test/package/package-new-from-slug.c
Expand Up @@ -70,5 +70,8 @@ main() {
}
}

curl_global_cleanup();
clib_package_cleanup();

return assert_failures();
}