mirror of
https://github.com/moparisthebest/pacman
synced 2024-08-13 17:03:46 -04:00
fixed a memory leak and avoided to modify a read-only parameter
This commit is contained in:
parent
ce6dcb5159
commit
a5e4fec74e
@ -59,69 +59,64 @@ PMList *sortbydeps(PMList *targets, int mode)
|
|||||||
int change = 1;
|
int change = 1;
|
||||||
int numscans = 0;
|
int numscans = 0;
|
||||||
int numtargs = 0;
|
int numtargs = 0;
|
||||||
int clean = 0;
|
|
||||||
|
|
||||||
if(targets == NULL) {
|
if(targets == NULL) {
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* count the number of targets */
|
for(i = targets; i; i = i->next) {
|
||||||
numtargs = pm_list_count(targets);
|
newtargs = pm_list_add(newtargs, i->data);
|
||||||
|
numtargs++;
|
||||||
|
}
|
||||||
|
|
||||||
while(change) {
|
while(change) {
|
||||||
|
PMList *tmptargs = NULL;
|
||||||
change = 0;
|
change = 0;
|
||||||
if(numscans > numtargs) {
|
if(numscans > numtargs) {
|
||||||
_alpm_log(PM_LOG_WARNING, "possible dependency cycle detected");
|
_alpm_log(PM_LOG_WARNING, "possible dependency cycle detected");
|
||||||
change = 0;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
newtargs = NULL;
|
|
||||||
numscans++;
|
numscans++;
|
||||||
/* run thru targets, moving up packages as necessary */
|
/* run thru targets, moving up packages as necessary */
|
||||||
for(i = targets; i; i = i->next) {
|
for(i = newtargs; i; i = i->next) {
|
||||||
pmpkg_t *p = (pmpkg_t*)i->data;
|
pmpkg_t *p = (pmpkg_t*)i->data;
|
||||||
for(j = p->depends; j; j = j->next) {
|
for(j = p->depends; j; j = j->next) {
|
||||||
pmdepend_t dep;
|
pmdepend_t dep;
|
||||||
int found = 0;
|
|
||||||
pmpkg_t *q = NULL;
|
pmpkg_t *q = NULL;
|
||||||
|
if(splitdep(j->data, &dep)) {
|
||||||
splitdep(j->data, &dep);
|
continue;
|
||||||
|
}
|
||||||
/* look for dep.name -- if it's farther down in the list, then
|
/* look for dep.name -- if it's farther down in the list, then
|
||||||
* move it up above p
|
* move it up above p
|
||||||
*/
|
*/
|
||||||
for(k = i->next; k && !found; k = k->next) {
|
for(k = i->next; k; k = k->next) {
|
||||||
q = (pmpkg_t *)k->data;
|
q = (pmpkg_t *)k->data;
|
||||||
if(!strcmp(dep.name, q->name)) {
|
if(!strcmp(dep.name, q->name)) {
|
||||||
found = 1;
|
if(!pkg_isin(q, tmptargs)) {
|
||||||
}
|
|
||||||
}
|
|
||||||
if(found) {
|
|
||||||
if(!pkg_isin(q, newtargs)) {
|
|
||||||
change = 1;
|
change = 1;
|
||||||
newtargs = pm_list_add(newtargs, q);
|
tmptargs = pm_list_add(tmptargs, q);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!pkg_isin(p, newtargs)) {
|
if(!pkg_isin(p, tmptargs)) {
|
||||||
newtargs = pm_list_add(newtargs, p);
|
tmptargs = pm_list_add(tmptargs, p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(clean && change) {
|
FREELISTPTR(newtargs);
|
||||||
/* free up targets -- it's local now */
|
newtargs = tmptargs;
|
||||||
FREELISTPTR(targets);
|
|
||||||
}
|
|
||||||
targets = newtargs;
|
|
||||||
clean = 1;
|
|
||||||
}
|
|
||||||
if(mode == PM_TRANS_TYPE_REMOVE) {
|
|
||||||
/* we're removing packages, so reverse the order */
|
|
||||||
newtargs = _alpm_list_reverse(targets);
|
|
||||||
/* free the old one */
|
|
||||||
FREELISTPTR(targets);
|
|
||||||
targets = newtargs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(targets);
|
if(mode == PM_TRANS_TYPE_REMOVE) {
|
||||||
|
/* we're removing packages, so reverse the order */
|
||||||
|
PMList *tmptargs = _alpm_list_reverse(newtargs);
|
||||||
|
/* free the old one */
|
||||||
|
FREELISTPTR(newtargs);
|
||||||
|
newtargs = tmptargs;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(newtargs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns a PMList* of missing_t pointers.
|
/* Returns a PMList* of missing_t pointers.
|
||||||
|
Loading…
Reference in New Issue
Block a user