aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2022-10-24 11:25:44 -0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2022-10-24 11:25:44 -0300
commite5e24ada4f5578ae921539280e4716a41bfd95cc (patch)
tree8c9f447b9e5623681715f0df777844b64753804b
parentb72f5188856df0abf45e1a707856bb4e4e86153c (diff)
downloadpahole-e5e24ada4f5578ae921539280e4716a41bfd95cc.tar.gz
core: Use zalloc() to make the code more robust
Recently we had a problem where it was assumed that a field was initialized to zeros but the constructor was using malloc(), check all use and switch cus__new() to zalloc() to prevent such problems. The other cases are clone() operations, so no sense in zeroing newly allocated memory since it will be copied from some other similar struct. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--dwarves.c5
1 files changed, 1 insertions, 4 deletions
diff --git a/dwarves.c b/dwarves.c
index 95a3bac0..b8681bcb 100644
--- a/dwarves.c
+++ b/dwarves.c
@@ -2586,12 +2586,9 @@ int cus__fprintf_load_files_err(struct cus *cus __maybe_unused, const char *tool
struct cus *cus__new(void)
{
- struct cus *cus = malloc(sizeof(*cus));
+ struct cus *cus = zalloc(sizeof(*cus));
if (cus != NULL) {
- cus->nr_entries = 0;
- cus->priv = NULL;
- cus->loader_exit = NULL;
INIT_LIST_HEAD(&cus->cus);
pthread_mutex_init(&cus->mutex, NULL);
}