mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-08 12:28:00 -05:00
libalpm/be_package.c: fix small memleak
file_pkg_ops can be a static struct like in other backends, we just need to initialize it at some point. Dan: add initialization flag. Signed-off-by: Xavier Chantry <chantry.xavier@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
62f5da3779
commit
281a4c0a4f
@ -122,27 +122,23 @@ static int _package_changelog_close(const pmpkg_t *pkg, void *fp)
|
|||||||
return( archive_read_finish((struct archive *)fp) );
|
return( archive_read_finish((struct archive *)fp) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Package file operations struct accessor. We implement this as a method
|
/** Package file operations struct accessor. We implement this as a method
|
||||||
* rather than a static struct as in be_files because we want to reuse the
|
* rather than a static struct as in be_files because we want to reuse the
|
||||||
* majority of the default_pkg_ops struct and add only a few operations of
|
* majority of the default_pkg_ops struct and add only a few operations of
|
||||||
* our own on top. The static file_pkg_ops variable inside this function
|
* our own on top.
|
||||||
* lets us only initialize an operations struct once which can always be
|
|
||||||
* accessed by this method.
|
|
||||||
*/
|
*/
|
||||||
static struct pkg_operations *get_file_pkg_ops(void)
|
static struct pkg_operations *get_file_pkg_ops(void)
|
||||||
{
|
{
|
||||||
static struct pkg_operations *file_pkg_ops = NULL;
|
static struct pkg_operations file_pkg_ops;
|
||||||
/* determine whether our static file_pkg_ops struct has been initialized */
|
static int file_pkg_ops_initialized = 0;
|
||||||
if(!file_pkg_ops) {
|
if(!file_pkg_ops_initialized) {
|
||||||
MALLOC(file_pkg_ops, sizeof(struct pkg_operations),
|
file_pkg_ops = default_pkg_ops;
|
||||||
RET_ERR(PM_ERR_MEMORY, NULL));
|
file_pkg_ops.changelog_open = _package_changelog_open;
|
||||||
memcpy(file_pkg_ops, &default_pkg_ops, sizeof(struct pkg_operations));
|
file_pkg_ops.changelog_read = _package_changelog_read;
|
||||||
file_pkg_ops->changelog_open = _package_changelog_open;
|
file_pkg_ops.changelog_close = _package_changelog_close;
|
||||||
file_pkg_ops->changelog_read = _package_changelog_read;
|
file_pkg_ops_initialized = 1;
|
||||||
file_pkg_ops->changelog_close = _package_changelog_close;
|
|
||||||
}
|
}
|
||||||
return(file_pkg_ops);
|
return(&file_pkg_ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user