Skip to content

Commit

Permalink
iconvcap: Don't leak the list of encodings
Browse files Browse the repository at this point in the history
This isn't a big deal since check_transitivity is only called once,
but fixing them silences Coverity Scan, so that's still nice.

#31
  • Loading branch information
debarshiray committed Oct 16, 2018
1 parent ebcbd60 commit 23efb62
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions iconvcap.c
Expand Up @@ -310,6 +310,20 @@ iconv_check(char **fromlist, char **tolist)
return 1;
}

static void
free_enclist (P_EncList enclist)
{
P_EncList p_e = enclist;
P_EncList p_e_next;

while (p_e != NULL) {
p_e_next = p_e->next;
free(p_e->enc);
free(p_e);
p_e = p_e_next;
}
}

/* check if conversion from any encoding not defined as NULL in file fname
to any other defined there is possible, in other words check transitivity
condition for all defined encodings (we then hope this condition holds
Expand Down Expand Up @@ -338,6 +352,7 @@ check_transitivity(char *fname)
fclose(f);
free(s);
free(p_e);
free_enclist(enclist);
return 1;
}
if ((sb = strchr(s, '"')) != NULL) {
Expand All @@ -346,6 +361,7 @@ check_transitivity(char *fname)
fclose(f);
free(s);
free(p_e);
free_enclist(enclist);
return 1;
}

Expand All @@ -369,12 +385,14 @@ check_transitivity(char *fname)
fprintf(stderr, "iconvap: iconv_open(%s, %s) failed\n",
enclist->enc, p_e->enc);
free(s);
free_enclist(enclist);
return 1;
}
if (iconv_check_one(p_e->enc, enclist->enc) != 0) {
fprintf(stderr, "iconvcap: iconv_open(%s, %s) failed\n",
p_e->enc, enclist->enc);
free(s);
free_enclist(enclist);
return 1;
}
}
Expand All @@ -383,6 +401,7 @@ check_transitivity(char *fname)

fprintf(stderr, "iconvcap: transitivity OK\n");
free(s);
free_enclist(enclist);
return 0;
}

Expand Down

0 comments on commit 23efb62

Please sign in to comment.