Commit 2958c1fe authored by Bernhard Link's avatar Bernhard Link

strlist_init_singleton frees the argument if not sucessful to behave more like...

strlist_init_singleton frees the argument if not sucessful to behave more like strlist_add and add some splint annotations
parent ed37bb2c
......@@ -34,7 +34,7 @@
extern int verbose;
/* get md5sums out of a "Packages.gz"-chunk. */
static retvalue binaries_parse_md5sum(const char *chunk,struct strlist *md5sums) {
static retvalue binaries_parse_md5sum(const char *chunk,/*@out@*/struct strlist *md5sums) {
retvalue r;
/* collect the given md5sum and size */
......@@ -64,19 +64,18 @@ static retvalue binaries_parse_md5sum(const char *chunk,struct strlist *md5sums)
}
r = strlist_init_singleton(md5sum,md5sums);
if( RET_WAS_ERROR(r) ) {
free(md5sum);
return r;
}
return RET_OK;
}
/* get somefields out of a "Packages.gz"-chunk. returns RET_OK on success, RET_NOTHING if incomplete, error otherwise */
static retvalue binaries_parse_chunk(const char *chunk,const char *packagename,const char *packagetype,const char *version,char **sourcename,char **basename) {
static retvalue binaries_parse_chunk(const char *chunk,const char *packagename,const char *packagetype,const char *version,/*@out@*/char **sourcename,/*@out@*/char **basename) {
retvalue r;
char *parch;
char *mysourcename,*mybasename;
assert(packagename);
assert(packagename!=NULL);
/* get the sourcename */
r = chunk_getname(chunk,"Source",&mysourcename,TRUE);
......@@ -131,8 +130,6 @@ static retvalue binaries_parse_getfilekeys(const char *chunk,struct strlist *fil
return r;
}
r = strlist_init_singleton(filename,files);
if( !RET_IS_OK(r) )
free(filename);
return r;
}
......@@ -148,9 +145,6 @@ retvalue binaries_calcfilekeys(const char *component,const char *sourcename,cons
if( !filekey )
return RET_ERROR_OOM;
r = strlist_init_singleton(filekey,filekeys);
if( RET_WAS_ERROR(r) ) {
free(filekey);
}
return r;
}
......@@ -163,7 +157,7 @@ static inline retvalue calcnewcontrol(const char *chunk,const char *sourcename,c
assert( filekeys->count == 1 );
*newchunk = chunk_replacefield(chunk,"Filename",filekeys->values[0]);
if( !*newchunk ) {
if( *newchunk == NULL ) {
strlist_done(filekeys);
return RET_ERROR_OOM;
}
......
......@@ -77,8 +77,10 @@ retvalue strlist_init_singleton(char *value,struct strlist *strlist) {
strlist->count = 1;
strlist->size = 1;
strlist->values = malloc(sizeof(char *));
if( strlist->values == NULL )
if( strlist->values == NULL ) {
free(value);
return RET_ERROR_OOM;
}
strlist->values[0] = value;
return RET_OK;
......@@ -180,7 +182,7 @@ retvalue strlist_dup(struct strlist *dest,const struct strlist *orig) {
if( !dest->values )
return RET_ERROR_OOM;
for( i = 0 ; i < dest->count ; i++ ) {
if( !(dest->values[i] = strdup(orig->values[i])) ) {
if( (dest->values[i] = strdup(orig->values[i])) == NULL ) {
strlist_done(dest);
return RET_ERROR_OOM;
}
......
......@@ -13,7 +13,7 @@ struct strlist {
retvalue strlist_init(/*@out@*/struct strlist *strlist);
retvalue strlist_init_n(int startsize,/*@out@*/struct strlist *strlist);
retvalue strlist_init_singleton(char *value,/*@out@*/struct strlist *strlist);
retvalue strlist_init_singleton(/*@only@*/char *value,/*@out@*/struct strlist *strlist);
void strlist_done(struct strlist *strlist);
/* add a string, will get property of the strlist and free'd by it */
......@@ -29,7 +29,7 @@ retvalue strlist_fprint(FILE *file,const struct strlist *strlist);
/* duplicate with content */
retvalue strlist_dup(struct strlist *dest,const struct strlist *orig);
/* replace the contents of dest with those from orig, which get emptied */
void strlist_move(struct strlist *dest,struct strlist *orig);
void strlist_move(/*@out@*/struct strlist *dest,struct strlist *orig);
/* empty orig and add everything to the end of dest, on error nothing is freed */
retvalue strlist_mvadd(struct strlist *dest,struct strlist *orig);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment