From 281a4c0a4f2de217b5d23939fb78b3bbfccc34ca Mon Sep 17 00:00:00 2001 From: Xavier Chantry Date: Sun, 17 Oct 2010 11:47:59 +0200 Subject: 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 Signed-off-by: Dan McGee --- lib/libalpm/be_package.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c index 4ea3eba8..42f33599 100644 --- a/lib/libalpm/be_package.c +++ b/lib/libalpm/be_package.c @@ -122,27 +122,23 @@ static int _package_changelog_close(const pmpkg_t *pkg, void *fp) return( archive_read_finish((struct archive *)fp) ); } - /** 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 * 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 - * lets us only initialize an operations struct once which can always be - * accessed by this method. + * our own on top. */ static struct pkg_operations *get_file_pkg_ops(void) { - static struct pkg_operations *file_pkg_ops = NULL; - /* determine whether our static file_pkg_ops struct has been initialized */ - if(!file_pkg_ops) { - MALLOC(file_pkg_ops, sizeof(struct pkg_operations), - RET_ERR(PM_ERR_MEMORY, NULL)); - memcpy(file_pkg_ops, &default_pkg_ops, sizeof(struct pkg_operations)); - file_pkg_ops->changelog_open = _package_changelog_open; - file_pkg_ops->changelog_read = _package_changelog_read; - file_pkg_ops->changelog_close = _package_changelog_close; + static struct pkg_operations file_pkg_ops; + static int file_pkg_ops_initialized = 0; + if(!file_pkg_ops_initialized) { + file_pkg_ops = default_pkg_ops; + file_pkg_ops.changelog_open = _package_changelog_open; + file_pkg_ops.changelog_read = _package_changelog_read; + file_pkg_ops.changelog_close = _package_changelog_close; + file_pkg_ops_initialized = 1; } - return(file_pkg_ops); + return(&file_pkg_ops); } /** -- cgit v1.2.3-24-g4f1b