]> git.itanic.dy.fi Git - rrdd/blobdiff - onewire_parser.c
onewire_parser: Fix double free corruption
[rrdd] / onewire_parser.c
index f07f7d9d45e095943d2a65f39dce6da87ce62ec6..12e3f5bf09c440ab0cebf06af87c394c1fa6f8e9 100644 (file)
@@ -173,6 +173,7 @@ undefined:
                        int fail, j;
                        char *tmp2;
 
+                       tmp = NULL;
                        pr_info("Reading data for entry %s with offset of %.2f\n",
                                ow_path, offset);
 
@@ -186,7 +187,10 @@ undefined:
                        for (j = 0; j < ret && *tmp2 == ' '; j++)
                                tmp2++;
 
-                       fail = !strncmp(tmp2, "85", 2);
+                       if (ret > 0)
+                               fail = !strncmp(tmp2, "85", 2);
+                       else
+                               fail = 1;
 
                        /*
                         * In case of failure, retry with uncached
@@ -206,7 +210,8 @@ undefined:
                                goto undefined;
                        }
                        retries++;
-                       free(tmp);
+                       if (tmp)
+                               free(tmp);
                }
 
                /* The data from OWNET_read appears to not be NULL terminated */