Commit 0fd329fd authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

archive: memory leak

parent 99caee42
...@@ -93,30 +93,32 @@ static int FindVolumes(access_t *p_access, struct archive *p_archive, const char ...@@ -93,30 +93,32 @@ static int FindVolumes(access_t *p_access, struct archive *p_archive, const char
uint16_t i_min; uint16_t i_min;
uint16_t i_max; uint16_t i_max;
} patterns[] = { } patterns[] = {
{ ".part1.rar", ".part%.1d.rar", 2, 9 }, { ".part1.rar", "%.*s.part%.1d.rar", 2, 9 },
{ ".part01.rar", ".part%.2d.rar", 2, 99 }, { ".part01.rar", "%.*s.part%.2d.rar", 2, 99 },
{ ".part001.rar", ".part%.3d.rar", 2, 999 }, { ".part001.rar", "%.*s.part%.3d.rar", 2, 999 },
{ ".001", ".%.3d", 2, 999 }, { ".001", "%.*s.%.3d", 2, 999 },
{ ".000", ".%.3d", 1, 999 }, { ".000", "%.*s.%.3d", 1, 999 },
}; };
const size_t i_uri_size = strlen(psz_uri); const int i_uri_size = strlen(psz_uri);
const int i_patterns = ARRAY_SIZE(patterns); const size_t i_patterns = ARRAY_SIZE(patterns);
for (int i=0; i<i_patterns; i++)
for (size_t i = 0; i < i_patterns; i++)
{ {
const size_t i_match_size = strlen(patterns[i].psz_match); const int i_match_size = strlen(patterns[i].psz_match);
if (i_uri_size < i_match_size) if (i_uri_size < i_match_size)
continue; continue;
if (!strcmp(&psz_uri[i_uri_size - i_match_size], patterns[i].psz_match)) if (!strcmp(&psz_uri[i_uri_size - i_match_size], patterns[i].psz_match))
{ {
char **ppsz_files = malloc(sizeof(char *) * patterns[i].i_max); char **ppsz_files = xmalloc(sizeof(char *) * patterns[i].i_max);
for(int j=patterns[i].i_min; j<patterns[i].i_max; j++) for (unsigned j = patterns[i].i_min; j < patterns[i].i_max; j++)
{ {
char *psz_newuri = strdup(psz_uri); char *psz_newuri;
if (!psz_newuri ||
!sprintf(&psz_newuri[i_uri_size - i_match_size], patterns[i].psz_format, j)) if (asprintf(&psz_newuri, patterns[i].psz_format,
i_uri_size - i_match_size, psz_uri, j) == -1)
break; break;
/* Probe URI */ /* Probe URI */
......
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