Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/rpm-software-management/createrepo_c.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavel Raiskup <praiskup@redhat.com>2022-08-09 08:58:39 +0300
committeramatej <matej.ales@seznam.cz>2022-11-03 18:51:36 +0300
commit04dbb52adf3955db866c381f1ab095391293af0a (patch)
tree74d069392817a1a129f5fd1c9c6aadbc44a56bf3
parentcad3ee75d0880b070e34d893c2ceb5e6a3bd027c (diff)
Better 'res' and 'pkg' allocation handling
The 'task_cleanup' target was reached without free-ing the 'pkg' structure in one of the error cases before. The 'res' was allocated on two places.
-rw-r--r--src/dumper_thread.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/src/dumper_thread.c b/src/dumper_thread.c
index 518b3a4..5e499ba 100644
--- a/src/dumper_thread.c
+++ b/src/dumper_thread.c
@@ -496,7 +496,6 @@ cr_dumper_thread(gpointer data, gpointer user_data)
udata->checksum_cachedir, location_href,
location_base, udata->changelog_limit,
NULL, hdrrflags, &tmp_err);
- pkg_new = pkg;
assert(pkg || tmp_err);
if (!pkg) {
@@ -507,14 +506,7 @@ cr_dumper_thread(gpointer data, gpointer user_data)
goto task_cleanup;
}
- res = cr_xml_dump(pkg, &tmp_err);
- if (tmp_err) {
- g_critical("Cannot dump XML for %s (%s): %s",
- pkg->name, pkg->pkgId, tmp_err->message);
- udata->had_errors = TRUE;
- g_clear_error(&tmp_err);
- goto task_cleanup;
- }
+ pkg_new = pkg; // We allocated, we clean
if (udata->output_pkg_list){
g_mutex_lock(&(udata->mutex_output_pkg_list));
@@ -524,14 +516,6 @@ cr_dumper_thread(gpointer data, gpointer user_data)
} else {
// Just gen XML from old loaded metadata
pkg = md;
- res = cr_xml_dump(md, &tmp_err);
- if (tmp_err) {
- g_critical("Cannot dump XML for %s (%s): %s",
- md->name, md->pkgId, tmp_err->message);
- udata->had_errors = TRUE;
- g_clear_error(&tmp_err);
- goto task_cleanup;
- }
}
#ifdef CR_DELTA_RPM_SUPPORT
@@ -570,6 +554,18 @@ cr_dumper_thread(gpointer data, gpointer user_data)
g_array_append_val(pkg_locations, location);
g_mutex_unlock(&(udata->mutex_nevra_table));
+ // Pre-calculate the XML data aside any critical section, and early enough
+ // so we can put it into the buffer (so buffered single-threaded write later
+ // is faster).
+ res = cr_xml_dump(pkg, &tmp_err);
+ if (tmp_err) {
+ g_critical("Cannot dump XML for %s (%s): %s",
+ pkg->name, pkg->pkgId, tmp_err->message);
+ udata->had_errors = TRUE;
+ g_clear_error(&tmp_err);
+ goto task_cleanup;
+ }
+
// Buffering stuff
g_mutex_lock(&(udata->mutex_buffer));
@@ -605,15 +601,15 @@ cr_dumper_thread(gpointer data, gpointer user_data)
// Dump XML and SQLite
write_pkg(task->id, res, pkg, udata);
- // Clean up
- if (pkg_new)
- cr_package_free(pkg_new);
-
g_free(res.primary);
g_free(res.filelists);
g_free(res.other);
task_cleanup:
+ // Clean up
+ if (pkg_new)
+ cr_package_free(pkg_new);
+
if (udata->id_pri <= task->id) {
// An error was encountered and we have to wait to increment counters
g_mutex_lock(&(udata->mutex_pri));