kernel: add missing memory allocation validation
@@ -33,13 +33,22 @@ struct flb_kernel *flb_kernel_info()
kernel = flb_malloc(sizeof(struct flb_kernel));
if (!kernel) {
+ flb_errno();
return NULL;
}
+
kernel->minor = 0;
kernel->major = 0;
kernel->patch = 0;
kernel->s_version.data = flb_malloc(16);
+ if (!kernel->s_version.data) {
+ flb_errno();
+ flb_free(kernel);
+ return NULL;
+ }
+
+
len = snprintf(kernel->s_version.data, 16, "0.0.0");
if (len == -1) {
perror("snprintf");
@@ -70,7 +79,7 @@ struct flb_kernel *flb_kernel_info()
struct flb_kernel *kernel;
if (uname(&uts) == -1) {
- perror("uname");
+ flb_errno();
return NULL;
}
len = strlen(uts.release);
@@ -111,6 +120,7 @@ struct flb_kernel *flb_kernel_info()
kernel = flb_malloc(sizeof(struct flb_kernel));
if (!kernel) {
+ flb_errno();
return NULL;
}
kernel->minor = a;
@@ -118,9 +128,16 @@ struct flb_kernel *flb_kernel_info()
kernel->patch = c;
kernel->s_version.data = flb_malloc(16);
+ if (!kernel->s_version.data) {
+ flb_errno();
+ flb_free(kernel);
+ return NULL;
+ }
+
len = snprintf(kernel->s_version.data, 16, "%i.%i.%i", a, b, c);
if (len == -1) {
- perror("snprintf");
+ flb_errno();
+ flb_free(kernel->s_version.data);
flb_free(kernel);
return NULL;
}
