Skip to content

Commit

Permalink
fix(clib-package): Double free
Browse files Browse the repository at this point in the history
  • Loading branch information
r10nw7fd3 authored and jwerle committed May 7, 2024
1 parent f19401c commit b1f455e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/common/clib-package.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#include "parse-repo/parse-repo.h"
#include "parson/parson.h"
#include "path-join/path-join.h"
#include "rimraf/rimraf.h"
#include "strdup/strdup.h"
#include "substr/substr.h"
#include "tempdir/tempdir.h"
#include "rimraf/rimraf.h"
#include <curl/curl.h>
#include <libgen.h>
#include <limits.h>
Expand Down Expand Up @@ -324,7 +324,7 @@ static inline list_t *parse_package_deps(JSON_Object *obj) {
if (!(dep = clib_package_dependency_new(name, version)))
goto loop_cleanup;

list_node_t* dep_node = list_node_new(dep);
list_node_t *dep_node = list_node_new(dep);
// note: if we fail to allocate the node itself,
// `dep` will never be pushed on the list
if (!dep_node) {
Expand Down Expand Up @@ -711,6 +711,7 @@ clib_package_new_from_slug_with_package_name(const char *slug, int verbose,
pkg->version = version;
} else {
free(version);
version = NULL;
}
}
} else {
Expand All @@ -724,6 +725,7 @@ clib_package_new_from_slug_with_package_name(const char *slug, int verbose,
pkg->author = author;
} else {
free(author);
author = NULL;
}
} else {
pkg->author = strdup(author);
Expand Down Expand Up @@ -1544,7 +1546,7 @@ int clib_package_install(clib_package_t *pkg, const char *dir, int verbose) {
#ifdef HAVE_PTHREADS
// Here there are i-1 threads running.
for (int j = 0; j < i; j++) {
fetch_package_file_thread_data_t *data = fetchs[j];
fetch_package_file_thread_data_t *data = fetchs[j];
int *status;

pthread_join(data->thread, (void **)&status);
Expand All @@ -1566,7 +1568,6 @@ int clib_package_install(clib_package_t *pkg, const char *dir, int verbose) {
}
#endif


install:
if (pkg->configure) {
E_FORMAT(&command, "cd %s/%s && %s", dir, pkg->name, pkg->configure);
Expand Down Expand Up @@ -1597,7 +1598,6 @@ int clib_package_install(clib_package_t *pkg, const char *dir, int verbose) {
pthread_mutex_unlock(&lock.mutex);
#endif


cleanup:
if (pkg_dir) {
if (0 != rc) {
Expand Down Expand Up @@ -1629,7 +1629,8 @@ int clib_package_install(clib_package_t *pkg, const char *dir, int verbose) {
#endif
if (0 != rc && pkg) {
clib_cache_delete_json(pkg->author, pkg->name, pkg->version);
_debug("deleted json cache: %s/%s@%s", pkg->author, pkg->name, pkg->version);
_debug("deleted json cache: %s/%s@%s", pkg->author, pkg->name,
pkg->version);
}
#ifdef HAVE_PTHREADS
pthread_mutex_unlock(&lock.mutex);
Expand Down

0 comments on commit b1f455e

Please sign in to comment.