[pacman-dev] [PATCH v3 1/4] pacman/upgrade: Check malloc() return value
Sören Brinkmann
soeren.brinkmann at gmail.com
Tue Mar 11 22:29:20 EDT 2014
Check the return value of malloc() before dereferencing the returned pointer.
Signed-off-by: Sören Brinkmann <soeren.brinkmann at gmail.com>
---
v2:
- add print statement to log the error
---
src/pacman/upgrade.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c
index 5416f6180b39..11da4dcb5e53 100644
--- a/src/pacman/upgrade.c
+++ b/src/pacman/upgrade.c
@@ -51,6 +51,10 @@ int pacman_upgrade(alpm_list_t *targets)
*/
for(i = targets; i; i = alpm_list_next(i)) {
int *r = malloc(sizeof(int));
+ if(r == NULL) {
+ pm_printf(ALPM_LOG_ERROR, _("memory exhausted\n"));
+ return 1;
+ }
if(strstr(i->data, "://")) {
char *str = alpm_fetch_pkgurl(config->handle, i->data);
--
1.9.0
More information about the pacman-dev
mailing list