[pacman-dev] [PATCH] Alpm, check for NULL in free-functions
Rikard Falkeborn
rikard.falkeborn at gmail.com
Sun Oct 25 11:39:27 UTC 2015
Also, use FREE() instead of free() in _alpm_backup_free()
to set the pointers to NULL.
Signed-off-by: Rikard Falkeborn <rikard.falkeborn at gmail.com>
---
lib/libalpm/backup.c | 7 ++++---
lib/libalpm/conflict.c | 2 ++
lib/libalpm/db.c | 1 +
lib/libalpm/delta.c | 1 +
lib/libalpm/deps.c | 2 ++
lib/libalpm/graph.c | 1 +
6 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/lib/libalpm/backup.c b/lib/libalpm/backup.c
index 5ccec03..3d1d6de 100644
--- a/lib/libalpm/backup.c
+++ b/lib/libalpm/backup.c
@@ -76,9 +76,10 @@ alpm_backup_t *_alpm_needbackup(const char *file, alpm_pkg_t *pkg)
void _alpm_backup_free(alpm_backup_t *backup)
{
- free(backup->name);
- free(backup->hash);
- free(backup);
+ ASSERT(backup != NULL, return);
+ FREE(backup->name);
+ FREE(backup->hash);
+ FREE(backup);
}
alpm_backup_t *_alpm_backup_dup(const alpm_backup_t *backup)
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 0af3e3a..41b8393 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -68,6 +68,7 @@ error:
*/
void SYMEXPORT alpm_conflict_free(alpm_conflict_t *conflict)
{
+ ASSERT(conflict != NULL, return);
FREE(conflict->package2);
FREE(conflict->package1);
FREE(conflict);
@@ -301,6 +302,7 @@ error:
*/
void SYMEXPORT alpm_fileconflict_free(alpm_fileconflict_t *conflict)
{
+ ASSERT(conflict != NULL, return);
FREE(conflict->ctarget);
FREE(conflict->file);
FREE(conflict->target);
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index b94d334..bb4c4bd 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -344,6 +344,7 @@ alpm_db_t *_alpm_db_new(const char *treename, int is_local)
void _alpm_db_free(alpm_db_t *db)
{
+ ASSERT(db != NULL, return);
/* cleanup pkgcache */
_alpm_db_free_pkgcache(db);
/* cleanup server list */
diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c
index a43269d..5ea2069 100644
--- a/lib/libalpm/delta.c
+++ b/lib/libalpm/delta.c
@@ -335,6 +335,7 @@ error:
void _alpm_delta_free(alpm_delta_t *delta)
{
+ ASSERT(delta != NULL, return);
FREE(delta->delta);
FREE(delta->delta_md5);
FREE(delta->from);
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 34ac8d3..f846b1c 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -37,6 +37,7 @@
void SYMEXPORT alpm_dep_free(alpm_depend_t *dep)
{
+ ASSERT(dep != NULL, return);
FREE(dep->name);
FREE(dep->version);
FREE(dep->desc);
@@ -63,6 +64,7 @@ error:
void SYMEXPORT alpm_depmissing_free(alpm_depmissing_t *miss)
{
+ ASSERT(miss != NULL, return);
alpm_dep_free(miss->depend);
FREE(miss->target);
FREE(miss->causingpkg);
diff --git a/lib/libalpm/graph.c b/lib/libalpm/graph.c
index 4d58169..7c3cce1 100644
--- a/lib/libalpm/graph.c
+++ b/lib/libalpm/graph.c
@@ -31,6 +31,7 @@ alpm_graph_t *_alpm_graph_new(void)
void _alpm_graph_free(void *data)
{
+ ASSERT(data != NULL, return);
alpm_graph_t *graph = data;
alpm_list_free(graph->children);
free(graph);
--
2.6.2
More information about the pacman-dev
mailing list