mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
test-skeleton: Support temporary files without memory leaks [BZ#18333]
add_temp_file now makes a copy which is freed by delete_temp_files. Callers to create_temp_file can now free the returned file name to avoid the memory leak. These changes do not affect the leak behavior of existing code. Also address a NULL pointer derefence in tzset after a memoru allocation failure, found during testing.
This commit is contained in:
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
|||||||
|
2015-04-27 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
|
[BZ#18333]
|
||||||
|
* time/tzset.c (parse_tzname): Return error on memory allocation
|
||||||
|
failure.
|
||||||
|
* test-skeleton.c (struct temp_name_list): Change type of name
|
||||||
|
member to non-const.
|
||||||
|
(add_temp_file): Create a copy of the file name.
|
||||||
|
(delete_temp_files): Deallocate memory.
|
||||||
|
(create_temp_file): Add comment.
|
||||||
|
|
||||||
2015-04-24 Florian Weimer <fweimer@redhat.com>
|
2015-04-24 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
* io/posix_fallocate.c (posix_fallocate): Do not set errno.
|
* io/posix_fallocate.c (posix_fallocate): Do not set errno.
|
||||||
|
2
NEWS
2
NEWS
@ -16,7 +16,7 @@ Version 2.22
|
|||||||
17967, 17969, 17978, 17987, 17991, 17996, 17998, 17999, 18019, 18020,
|
17967, 17969, 17978, 17987, 17991, 17996, 17998, 17999, 18019, 18020,
|
||||||
18029, 18030, 18032, 18036, 18038, 18039, 18042, 18043, 18046, 18047,
|
18029, 18030, 18032, 18036, 18038, 18039, 18042, 18043, 18046, 18047,
|
||||||
18068, 18080, 18093, 18100, 18104, 18110, 18111, 18128, 18138, 18185,
|
18068, 18080, 18093, 18100, 18104, 18110, 18111, 18128, 18138, 18185,
|
||||||
18197, 18206, 18210, 18211, 18247, 18287.
|
18197, 18206, 18210, 18211, 18247, 18287, 18333.
|
||||||
|
|
||||||
* Cache information can be queried via sysconf() function on s390 e.g. with
|
* Cache information can be queried via sysconf() function on s390 e.g. with
|
||||||
_SC_LEVEL1_ICACHE_SIZE as argument.
|
_SC_LEVEL1_ICACHE_SIZE as argument.
|
||||||
|
@ -73,7 +73,7 @@ static const char *test_dir;
|
|||||||
struct temp_name_list
|
struct temp_name_list
|
||||||
{
|
{
|
||||||
struct qelem q;
|
struct qelem q;
|
||||||
const char *name;
|
char *name;
|
||||||
} *temp_name_list;
|
} *temp_name_list;
|
||||||
|
|
||||||
/* Add temporary files in list. */
|
/* Add temporary files in list. */
|
||||||
@ -83,14 +83,17 @@ add_temp_file (const char *name)
|
|||||||
{
|
{
|
||||||
struct temp_name_list *newp
|
struct temp_name_list *newp
|
||||||
= (struct temp_name_list *) calloc (sizeof (*newp), 1);
|
= (struct temp_name_list *) calloc (sizeof (*newp), 1);
|
||||||
if (newp != NULL)
|
char *newname = strdup (name);
|
||||||
|
if (newp != NULL && newname != NULL)
|
||||||
{
|
{
|
||||||
newp->name = name;
|
newp->name = newname;
|
||||||
if (temp_name_list == NULL)
|
if (temp_name_list == NULL)
|
||||||
temp_name_list = (struct temp_name_list *) &newp->q;
|
temp_name_list = (struct temp_name_list *) &newp->q;
|
||||||
else
|
else
|
||||||
insque (newp, temp_name_list);
|
insque (newp, temp_name_list);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
free (newp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delete all temporary files. */
|
/* Delete all temporary files. */
|
||||||
@ -100,11 +103,19 @@ delete_temp_files (void)
|
|||||||
while (temp_name_list != NULL)
|
while (temp_name_list != NULL)
|
||||||
{
|
{
|
||||||
remove (temp_name_list->name);
|
remove (temp_name_list->name);
|
||||||
temp_name_list = (struct temp_name_list *) temp_name_list->q.q_forw;
|
free (temp_name_list->name);
|
||||||
|
|
||||||
|
struct temp_name_list *next
|
||||||
|
= (struct temp_name_list *) temp_name_list->q.q_forw;
|
||||||
|
free (temp_name_list);
|
||||||
|
temp_name_list = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a temporary file. */
|
/* Create a temporary file. Return the opened file descriptor on
|
||||||
|
success, or -1 on failure. Write the file name to *FILENAME if
|
||||||
|
FILENAME is not NULL. In this case, the caller is expected to free
|
||||||
|
*FILENAME. */
|
||||||
static int
|
static int
|
||||||
__attribute__ ((unused))
|
__attribute__ ((unused))
|
||||||
create_temp_file (const char *base, char **filename)
|
create_temp_file (const char *base, char **filename)
|
||||||
@ -132,6 +143,8 @@ create_temp_file (const char *base, char **filename)
|
|||||||
add_temp_file (fname);
|
add_temp_file (fname);
|
||||||
if (filename != NULL)
|
if (filename != NULL)
|
||||||
*filename = fname;
|
*filename = fname;
|
||||||
|
else
|
||||||
|
free (fname);
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,12 @@ parse_tzname (const char **tzp, int whichrule)
|
|||||||
if (*p++ != '>' || len < 3)
|
if (*p++ != '>' || len < 3)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tz_rules[whichrule].name = __tzstring_len (start, len);
|
|
||||||
|
const char *name = __tzstring_len (start, len);
|
||||||
|
if (name == NULL)
|
||||||
|
return false;
|
||||||
|
tz_rules[whichrule].name = name;
|
||||||
|
|
||||||
*tzp = p;
|
*tzp = p;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user