Check for successful allocation of multiple memory ranges, and release
partial allocations in the error path when one of them failed. This
fixes a potential memory leak, as well as avoids NULL dereferences.
This was reported by clang's scan-build.
packet.type = SR_DF_ANALOG;
packet.payload = &analog;
analog.meaning->mqflags = 0;
- if (!(temp = g_try_malloc(sizeof(float) * samples)))
- break;
- if (!(rh = g_try_malloc(sizeof(float) * samples)))
+ temp = g_try_malloc(sizeof(float) * samples);
+ rh = g_try_malloc(sizeof(float) * samples);
+ if (!temp || !rh) {
+ g_free(temp);
+ g_free(rh);
break;
+ }
for (i = 0, j = 0; i < samples; i++) {
/* Both Celsius and Fahrenheit stored at base -40. */
if (devc->temp_unit == 0)