Skip to contentSkip to conversation

libsensors: Exit with fatal error if

PATCH In review Andre Prendel 2 participants 2 messages Feb 20, 2009 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 libsensors: Exit with fatal error if

If str(n)dup fails, there is no more memory left. We should exit with "Out of memory".

---
 init.c  |    3 +++
 sysfs.c |    8 ++++++++
 2 files changed, 11 insertions(+)
lib/init.c +3 -0
@@ -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");
 	}
 
lib/sysfs.c +8 -0
@@ -188,9 +188,14 @@ char *get_feature_name(sensors_feature_t
 	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(sen
 		/* 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);

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#1 lore raw

Hi Andre,

Quoted 38 lines · Andre Prendel

If str(n)dup fails, there is no more memory left. We should exit with "Out of memory".

---
 init.c  |    3 +++
 sysfs.c |    8 ++++++++
 2 files changed, 11 insertions(+)
lib/init.c +3 -0
@@ -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");
 	}
 
lib/sysfs.c +5 -0
@@ -188,9 +188,14 @@ char *get_feature_name(sensors_feature_t
 	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;

lib/sysfs.c static int sensors_read_dynamic_chip(sen · line 432

Quoted 9 lines
lib/sysfs.c +3 -0
@@ -419,6 +424,9 @@ static int sensors_read_dynamic_chip(sen
 		/* 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);

Looks good. Applied, thanks!

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors