fix: prevent reallocing previous memory used by lm_ctx_resolve

This commit is contained in:
ngn 2024-08-22 08:40:29 +03:00
parent 4f4db1963d
commit 91dcbd5507
2 changed files with 28 additions and 26 deletions

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-22 03:32+0300\n"
"POT-Creation-Date: 2024-08-22 08:37+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -204,7 +204,7 @@ msgstr "Failed to run the editor: %s"
msgid "Failed to open the editor: %s"
msgstr "Failed to open the editor: %s"
#: src/cmd/info.c:13 src/cmd/info.c:23 src/cmd/install.c:92 src/cmd/remove.c:53
#: src/cmd/info.c:13 src/cmd/info.c:23 src/cmd/install.c:94 src/cmd/remove.c:53
msgid "Package "
msgstr "Package "
@ -294,67 +294,67 @@ msgstr "There are no avaliable pools, have you synced yet?"
msgid "Specified "
msgstr "Specified "
#: src/cmd/install.c:73
#: src/cmd/install.c:76
msgid "Failed to load "
msgstr "Failed to load "
#: src/cmd/install.c:83 src/cmd/remove.c:55
#: src/cmd/install.c:85 src/cmd/remove.c:55
msgid "Failed to find "
msgstr "Failed to find "
#: src/cmd/install.c:101
#: src/cmd/install.c:103
msgid "Failed to resolve "
msgstr "Failed to resolve "
#: src/cmd/install.c:110
#: src/cmd/install.c:112
msgid "Nothing to do (no packages to install)"
msgstr "Nothing to do (no packages to install)"
#: src/cmd/install.c:119 src/cmd/install.c:121 src/cmd/remove.c:75
#: src/cmd/install.c:121 src/cmd/install.c:123 src/cmd/remove.c:75
#: src/cmd/remove.c:77 src/cmd/update.c:50 src/cmd/update.c:52
msgid "Following "
msgstr "Following "
#: src/cmd/install.c:127 src/cmd/remove.c:84
#: src/cmd/install.c:129 src/cmd/remove.c:84
msgid "Total of "
msgstr "Total of "
#: src/cmd/install.c:130 src/cmd/update.c:59
#: src/cmd/install.c:132 src/cmd/update.c:59
#, c-format
msgid "Root directory is modified, install scripts will be saved in %s"
msgstr "Root directory is modified, install scripts will be saved in %s"
#: src/cmd/install.c:132 src/cmd/remove.c:85 src/cmd/update.c:61
#: src/cmd/install.c:134 src/cmd/remove.c:85 src/cmd/update.c:61
msgid "Continue?"
msgstr "Continue?"
#: src/cmd/install.c:133 src/cmd/remove.c:86 src/cmd/update.c:62
#: src/cmd/install.c:135 src/cmd/remove.c:86 src/cmd/update.c:62
msgid "Operation cancelled"
msgstr "Operation cancelled"
#: src/cmd/install.c:149 src/cmd/install.c:153 src/cmd/install.c:173
#: src/cmd/install.c:189 src/cmd/remove.c:93 src/cmd/update.c:72
#: src/cmd/install.c:151 src/cmd/install.c:155 src/cmd/install.c:175
#: src/cmd/install.c:191 src/cmd/remove.c:93 src/cmd/update.c:72
#: src/cmd/update.c:83 src/cmd/update.c:94
msgid "("
msgstr "("
#: src/cmd/install.c:159 src/cmd/update.c:78
#: src/cmd/install.c:161 src/cmd/update.c:78
msgid "Failed to download "
msgstr "Failed to download "
#: src/cmd/install.c:180 src/cmd/remove.c:100 src/cmd/update.c:89
#: src/cmd/install.c:182 src/cmd/remove.c:100 src/cmd/update.c:89
msgid "Failed to remove "
msgstr "Failed to remove "
#: src/cmd/install.c:196 src/cmd/update.c:100
#: src/cmd/install.c:198 src/cmd/update.c:100
msgid "Failed to install "
msgstr "Failed to install "
#: src/cmd/install.c:203
#: src/cmd/install.c:205
msgid "Installed "
msgstr "Installed "
#: src/cmd/install.c:203
#: src/cmd/install.c:205
msgid "Installed all of the "
msgstr "Installed all of the "

View File

@ -47,7 +47,7 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
ssize_t current = 0, size = 0, save = 0, li = 0;
bool ret = false, r = false, is_local = false;
lm_pkg_t *pkg = NULL, *locals = NULL;
lm_pkg_t *pkg = NULL, **locals = NULL;
lm_ctx_resolve_list_t *list = NULL;
lm_entry_t older;
char ssize[LONGSTR_MAX+3];
@ -57,7 +57,7 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
if(NULL != args->list[i].name || NULL == (name = args->list[i].value))
continue;
// if thiş is a local archive, load it
// if this is a local archive, load it
if(endswith(name, ".mpf") && access(name, F_OK) == 0){
if(access(name, R_OK) != 0){
error(_("Specified "FG_BOLD"%s"FG_RESET" archive does not have read access"), name);
@ -65,16 +65,18 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
}
if(NULL == locals)
locals = malloc(sizeof(lm_pkg_t));
locals = malloc(sizeof(lm_pkg_t*));
else
locals = realloc(locals, sizeof(lm_pkg_t)*((++li)+1));
locals = realloc(locals, sizeof(lm_pkg_t*)*((++li)+1));
if(!lm_ctx_package_from(ctx, &locals[li], name)){
pkg = malloc(sizeof(lm_pkg_t));
locals[li] = pkg;
if(!lm_ctx_package_from(ctx, pkg, name)){
error(_("Failed to load "FG_BOLD"%s"FG_RESET": %s"), name, lm_strerror());
goto end;
}
pkg = &locals[li];
goto resolve;
}
@ -139,7 +141,7 @@ bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args){
is_local = false;
for(size_t i = 0; i < (li+1) && NULL != locals; i++){
if(lm_package_is_same(&locals[i], pkg)){
if(lm_package_is_same(locals[i], pkg)){
is_local = true;
break;
}
@ -208,7 +210,7 @@ end:
bar_free();
for(size_t i = 0; i < (li+1) && NULL != locals; i++)
lm_ctx_package_from_free(&locals[li]);
lm_ctx_package_from_free(locals[li]);
free(locals);
lm_ctx_resolve_free(list);