Skip to content

Commit

Permalink
Set some things NULL when we dealloc
Browse files Browse the repository at this point in the history
  • Loading branch information
laffer1 committed Feb 5, 2022
1 parent 0f6b86e commit c8766fc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
16 changes: 7 additions & 9 deletions libmport/clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ mport_clean_oldpackages(mportInstance *mport)

asprintf(&path, "%s/%s", MPORT_FETCH_STAGING_DIR, de->d_name);
if (path == NULL) {
if (indexEntry != NULL)
if (indexEntry != NULL) {
mport_index_entry_free_vec(indexEntry);
indexEntry = NULL;
}
continue;
}

Expand All @@ -94,24 +96,20 @@ mport_clean_oldpackages(mportInstance *mport)
}
} else if (mport_verify_hash(path, (*indexEntry)->hash) == 0) {
if (unlink(path) < 0) {

error_code = SET_ERRORX(MPORT_ERR_FATAL, "Could not delete file %s: %s",

path, strerror(errno));

error_code = SET_ERRORX(MPORT_ERR_FATAL, "Could not delete file %s: %s", path, strerror(errno));
mport_call_msg_cb(mport, "%s\n", mport_err_string());

} else {

deleted++;

}
mport_index_entry_free_vec(indexEntry);
indexEntry = NULL;
} else {
mport_index_entry_free_vec(indexEntry);
indexEntry = NULL;
}

free(path);
path = NULL;
}

closedir(d);
Expand Down
6 changes: 6 additions & 0 deletions libmport/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ mport_download(mportInstance *mport, const char *packageName, char **path) {
asprintf(path, "%s/%s", MPORT_LOCAL_PKG_PATH, (*indexEntry)->bundlefile);
if (path == NULL) {
mport_index_entry_free_vec(indexEntry);
indexEntry = NULL;
SET_ERRORX(1, "%s", "Unable to allocate memory for path.");
RETURN_CURRENT_ERROR;
}
Expand All @@ -276,7 +277,9 @@ mport_download(mportInstance *mport, const char *packageName, char **path) {
if (mport_fetch_bundle(mport, (*indexEntry)->bundlefile) != MPORT_OK) {
mport_call_msg_cb(mport, "Error fetching package %s, %s", packageName, mport_err_string());
free(*path);
path = NULL;
mport_index_entry_free_vec(indexEntry);
indexEntry = NULL;
return mport_err_code();

}
Expand All @@ -293,7 +296,9 @@ mport_download(mportInstance *mport, const char *packageName, char **path) {
}
}
free(*path);
path = NULL;
mport_index_entry_free_vec(indexEntry);
indexEntry = NULL;
SET_ERRORX(1, "Package %s fails hash verification.", packageName);
RETURN_CURRENT_ERROR;
}
Expand All @@ -304,6 +309,7 @@ mport_download(mportInstance *mport, const char *packageName, char **path) {
mport_call_msg_cb(mport, "Package %s exists at %s\n", packageName, *path);

mport_index_entry_free_vec(indexEntry);
indexEntry = NULL;

return (0);
}
Expand Down
2 changes: 2 additions & 0 deletions libmport/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ mport_index_check(mportInstance *mport, mportPackageMeta *pack) {
indexEntries++;
}
mport_index_entry_free_vec(indexEntries_orig);
indexEntries_orig = NULL;
indexEntries = NULL;
}

return (ret);
Expand Down
8 changes: 8 additions & 0 deletions libmport/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ mport_install(mportInstance *mport, const char *pkgname, const char *version, co
}
if (e[e_loc] == NULL) {
mport_index_entry_free_vec(e);
e = NULL;
RETURN_ERRORX(MPORT_ERR_FATAL, "Could not resolve '%s-%s'.", pkgname, version);
}
} else {
Expand All @@ -84,13 +85,16 @@ mport_install(mportInstance *mport, const char *pkgname, const char *version, co
asprintf(&filename, "%s/%s", MPORT_FETCH_STAGING_DIR, e[e_loc]->bundlefile);
if (filename == NULL) {
mport_index_entry_free_vec(e);
e = NULL;
RETURN_ERROR(MPORT_ERR_FATAL, "Out of memory.");
}

if (!mport_file_exists(filename)) {
if (mport_fetch_bundle(mport, e[e_loc]->bundlefile) != MPORT_OK) {
free(filename);
filename = NULL;
mport_index_entry_free_vec(e);
e = NULL;
RETURN_CURRENT_ERROR;
}
}
Expand All @@ -100,17 +104,21 @@ mport_install(mportInstance *mport, const char *pkgname, const char *version, co

if (unlink(filename) == 0) {
free(filename);
filename = NULL;
RETURN_ERROR(MPORT_ERR_FATAL, "Package failed hash verification and was removed.\n");
} else {
free(filename);
filename = NULL;
RETURN_ERROR(MPORT_ERR_FATAL, "Package failed hash verification, but could not be removed.\n");
}
}

ret = mport_install_primative(mport, filename, prefix, automatic);

free(filename);
filename = NULL;
mport_index_entry_free_vec(e);
e = NULL;

return ret;
}
Expand Down

0 comments on commit c8766fc

Please sign in to comment.