Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
authorXavier Chantry <chantry.xavier@gmail.com>2010-10-17 11:47:59 +0200
committerDan McGee <dan@archlinux.org>2011-01-07 21:27:39 -0600
commit281a4c0a4f2de217b5d23939fb78b3bbfccc34ca (patch)
treec24560c3d6ad509bb506720f0fbfaf6d4586c4f7 /lib/libalpm
parent62f5da377920c4e7823c4f8b8fb3673c9c2739e9 (diff)
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>
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/be_package.c24
1 files 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);
}
/**