File libcdio-0.94-leak-01.patch of Package libcdio.24379
Partial patch.
From 490e1e26d7b34d99a6fbfaa6a923ccdc546bba2f Mon Sep 17 00:00:00 2001
From: "R. Bernstein" <rocky@gnu.org>
Date: Sun, 19 Nov 2017 22:39:38 -0500
Subject: [PATCH 1/20] Remove more memory leaks (via valgrind)
---
NEWS | 3 ++-
lib/driver/image/nrg.c | 9 ++++-----
test/driver/logger.c | 16 ++++++++++++++++
3 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/lib/driver/image/nrg.c b/lib/driver/image/nrg.c
index 9e2eb484..af51db21 100644
--- a/lib/driver/image/nrg.c
+++ b/lib/driver/image/nrg.c
@@ -1268,18 +1268,17 @@ _get_track_green_nrg(void *p_user_data, track_t track_num)
bool
cdio_is_nrg(const char *psz_nrg)
{
- _img_private_t env;
+ _img_private_t *p_env = calloc(1, sizeof (_img_private_t));
bool is_nrg = false;
if (psz_nrg == NULL) return false;
- memset(&env, 0, sizeof(env));
- if (!(env.gen.data_source = cdio_stdio_new (psz_nrg))) {
+ if (!(p_env->gen.data_source = cdio_stdio_new (psz_nrg))) {
cdio_warn ("can't open nrg image file %s for reading", psz_nrg);
return false;
}
- if (parse_nrg(&env, psz_nrg, CDIO_LOG_INFO)) {
+ if (parse_nrg(p_env, psz_nrg, CDIO_LOG_INFO)) {
is_nrg = true;
#ifdef ALSO_TEST_NAME
size_t psz_len;
@@ -1290,7 +1289,7 @@ cdio_is_nrg(const char *psz_nrg)
is_nrg = strncasecmp( psz_nrg+(psz_len-3), "nrg", 3 ) == 0;
#endif
}
- cdio_stdio_destroy(env.gen.data_source);
+ _free_nrg(p_env);
return is_nrg;
}
diff --git a/test/driver/logger.c b/test/driver/logger.c
index 519febb1..1a0bf72d 100644
--- a/test/driver/logger.c
+++ b/test/driver/logger.c
@@ -84,29 +84,37 @@ main(int argc, const char *argv[])
strncmp(test_msg, last_debugmsg, strlen(test_msg)) != 0) {
fprintf(stderr, "debug message %s did not get handled\n",
last_debugmsg);
+ free(last_debugmsg);
exit(2);
}
+ free(last_debugmsg);
test_msg = "info";
cdio_info("%s", test_msg);
if (strncmp(test_msg, last_infomsg, strlen(test_msg)) != 0) {
fprintf(stderr, "info message %s did not get handled\n", last_infomsg);
+ free(last_infomsg);
exit(3);
}
+ free(last_infomsg);
test_msg = "warn";
cdio_warn("%s", test_msg);
if (strncmp(test_msg, last_warnmsg, strlen(test_msg)) != 0) {
fprintf(stderr, "warn message %s did not get handled\n", last_warnmsg);
+ free(last_warnmsg);
exit(4);
}
+ free(last_warnmsg);
test_msg = "error";
cdio_error("%s", test_msg);
if (strncmp(test_msg, last_errmsg, strlen(test_msg)) != 0) {
fprintf(stderr, "error message %s did not get handled\n", last_errmsg);
+ free(last_errmsg);
exit(5);
}
+ free(last_errmsg);
/* Try using generic cdio_log routine */
@@ -114,29 +122,37 @@ main(int argc, const char *argv[])
cdio_log(CDIO_LOG_DEBUG, "%s", test_msg);
if (strncmp(test_msg, last_debugmsg, strlen(test_msg)) != 0) {
fprintf(stderr, "debug message %s did not get handled, phase 2\n", last_debugmsg);
+ free(last_debugmsg);
exit(6);
}
+ free(last_debugmsg);
test_msg = "info via cdio_log";
cdio_log(CDIO_LOG_INFO, "%s", test_msg);
if (strncmp(test_msg, last_infomsg, strlen(test_msg)) != 0) {
fprintf(stderr, "info message %s did not get handled\n", last_infomsg);
+ free(last_infomsg);
exit(7);
}
+ free(last_infomsg);
test_msg = "warn via cdio_log";
cdio_log(CDIO_LOG_WARN, "%s", test_msg);
if (strncmp(test_msg, last_warnmsg, strlen(test_msg)) != 0) {
fprintf(stderr, "warn message %s did not get handled\n", last_warnmsg);
+ free(last_warnmsg);
exit(8);
}
+ free(last_warnmsg);
test_msg = "error via cdio_log";
cdio_log(CDIO_LOG_ERROR, "%s", test_msg);
if (strncmp(test_msg, last_errmsg, strlen(test_msg)) != 0) {
fprintf(stderr, "error message %s did not get handled\n", last_errmsg);
+ free(last_errmsg);
exit(9);
}
+ free(last_errmsg);
exit(0);
}
--
2.17.0