Author: mlschroe Date: Mon Aug 25 15:13:22 2008 New Revision: 10897 URL: http://svn.opensuse.org/viewcvs/zypp?rev=10897&view=rev Log: - fix memory leaks, clean up a bit Modified: trunk/sat-solver/tools/repo_rpmmd.c Modified: trunk/sat-solver/tools/repo_rpmmd.c URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/repo_rpmmd.c?rev=10897&r1=10896&r2=10897&view=diff ============================================================================== --- trunk/sat-solver/tools/repo_rpmmd.c (original) +++ trunk/sat-solver/tools/repo_rpmmd.c Mon Aug 25 15:13:22 2008 @@ -686,30 +686,16 @@ one. */ const char *pkgid; - if ( (pkgid = find_attr("pkgid", atts)) != NULL ) + if ((pkgid = find_attr("pkgid", atts)) != NULL) { - int found = 0; - /*const char *name = find_attr("name", atts);*/ // look at the checksum cache - Id index = stringpool_str2id (&pd->cspool, pkgid, 1 /* create it */); - if ( index < pd->ncscache ) - { - Id solvid = pd->cscache[index-1]; - /* printf */ - if ( solvid > 0 ) - { - Solvable *s = pool_id2solvable(pool, solvid); - /* we found the already defined package */ - pd->solvable = s; - found = 1; - /*fprintf(stderr, "package found %s-%s.\n", name, find_attr("arch", atts));*/ - } - } - if ( ! found ) - { + Id index = stringpool_str2id(&pd->cspool, pkgid, 0); + if (!index || index >= pd->ncscache || !pd->cscache[index]) + { fprintf(stderr, "error, the repository specifies extra information about package with checksum '%s', which does not exist in the repository.\n", pkgid); exit(1); - } + } + pd->solvable = pool_id2solvable(pool, pd->cscache[index]); } else { @@ -954,7 +940,7 @@ case STATE_CHECKSUM: { int l; - Id type; + Id type, index; if (!strcasecmp (pd->tmpattr, "sha") || !strcasecmp (pd->tmpattr, "sha1")) l = SIZEOF_SHA1 * 2, type = REPOKEY_TYPE_SHA1; else if (!strcasecmp (pd->tmpattr, "md5")) @@ -972,19 +958,15 @@ repodata_set_checksum(pd->data, handle, SOLVABLE_CHECKSUM, type, pd->content); /* we save the checksum to solvable id relationship for extended metadata */ - Id index = stringpool_str2id (&pd->cspool, pd->content, 1 /* create it */); - if ( index >= pd->ncscache ) - { - /** realloc for this index plus CSREALLOC_STEP*/ - pd->cscache = (Id *) sat_zextend(pd->cscache, pd->ncscache, index - pd->ncscache +1, sizeof(Id), 255); - /** fill the realloced part with 0s */ - - pd->ncscache = index +1; - - } + index = stringpool_str2id(&pd->cspool, pd->content, 1 /* create it */); + if (index >= pd->ncscache) + { + pd->cscache = sat_zextend(pd->cscache, pd->ncscache, index + 1 - pd->ncscache, sizeof(Id), 255); + pd->ncscache = index + 1; + } /* add the checksum to the cache */ pd->cscache[index-1] = s - pool->solvables; - break; + break; } case STATE_FILE: #if 0 @@ -1141,8 +1123,6 @@ the package checksums we know about, to get an Id we can use in a cache */ stringpool_init_empty(&pd.cspool); - pd.cscache = (Id *) calloc(MAX_CSCACHE, sizeof(Id)); - pd.ncscache = MAX_CSCACHE; XML_Parser parser = XML_ParserCreate(NULL); XML_SetUserData(parser, &pd); @@ -1166,4 +1146,6 @@ repodata_internalize(pd.data); sat_free(pd.content); join_freemem(); + stringpool_free(&pd.cspool); + sat_free(pd.cscache); } -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org