From c1a066a3075f4f93e40dd53d2c656c2c7ea1d1a0 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Fri, 20 Feb 2009 10:56:52 +0000 Subject: [PATCH] If str(n)dup fails, there is no more memory left. We should exit with "Out of memory". Patch from Andre Prendel. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5661 7894878c-1315-0410-8ee3-d5d059ff63e0 --- lib/init.c | 3 +++ lib/sysfs.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/init.c b/lib/init.c index b5a98c3f..d0c7a5c2 100644 --- a/lib/init.c +++ b/lib/init.c @@ -53,6 +53,9 @@ static int sensors_parse(void) locale = setlocale(LC_ALL, NULL); if (locale) { locale = strdup(locale); + if (!locale) + sensors_fatal_error(__func__, "Out of memory"); + setlocale(LC_ALL, "C"); } diff --git a/lib/sysfs.c b/lib/sysfs.c index 4c383eb5..0dd0afcc 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -188,9 +188,14 @@ char *get_feature_name(sensors_feature_type ftype, char *sfname) case SENSORS_FEATURE_CURR: underscore = strchr(sfname, '_'); name = strndup(sfname, underscore - sfname); + if (!name) + sensors_fatal_error(__func__, "Out of memory"); + break; default: name = strdup(sfname); + if (!name) + sensors_fatal_error(__func__, "Out of memory"); } return name; @@ -419,6 +424,9 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip, /* fill in the subfeature members */ all_subfeatures[i].type = sftype; all_subfeatures[i].name = strdup(name); + if (!all_subfeatures[i].name) + sensors_fatal_error(__func__, "Out of memory"); + if (!(sftype & 0x80)) all_subfeatures[i].flags |= SENSORS_COMPUTE_MAPPING; all_subfeatures[i].flags |= sensors_get_attr_mode(dev_path, name);