Call realloc() correctly in aom_fast9_detect()

Save the return value of realloc() in a new variable so that we don't
lose the original `ret_corners` value if realloc() returns NULL.

Declare the `corners` parameter of aom_fast9_score() as a pointer to
const.

Have fast_9.c include fast.h instead of duplicating the typedefs.

Change-Id: I03be930620778bfd4dfb270d83af655f12046f78
diff --git a/third_party/fastfeat/fast.h b/third_party/fastfeat/fast.h
index 86a586b..7e3e155 100644
--- a/third_party/fastfeat/fast.h
+++ b/third_party/fastfeat/fast.h
@@ -40,7 +40,7 @@
 
 xy* aom_fast9_detect(const byte* im, int xsize, int ysize, int stride, int b, int* ret_num_corners);
 
-int* aom_fast9_score(const byte* i, int stride, xy* corners, int num_corners, int b);
+int* aom_fast9_score(const byte* i, int stride, const xy* corners, int num_corners, int b);
 
 xy* aom_fast9_detect_nonmax(const byte* im, int xsize, int ysize, int stride, int b,
                             int** ret_scores, int* ret_num_corners, bool* mem_alloc_failed);
diff --git a/third_party/fastfeat/fast_9.c b/third_party/fastfeat/fast_9.c
index 345c37f..de55ab5 100644
--- a/third_party/fastfeat/fast_9.c
+++ b/third_party/fastfeat/fast_9.c
@@ -31,9 +31,7 @@
 // clang-format off
 /*This is mechanically generated code*/
 #include <stdlib.h>
-
-typedef struct { int x, y; } xy;
-typedef unsigned char byte;
+#include "fast.h"
 
 int aom_fast9_corner_score(const byte* p, const int pixel[], int bstart)
 {
@@ -2988,7 +2986,7 @@
 
 
 
-int* aom_fast9_score(const byte* i, int stride, xy* corners, int num_corners, int b)
+int* aom_fast9_score(const byte* i, int stride, const xy* corners, int num_corners, int b)
 {
   int* scores = (int*)malloc(sizeof(int)* num_corners);
   int n;
@@ -5927,8 +5925,13 @@
       if(num_corners == rsize)
       {
         rsize*=2;
-        ret_corners = (xy*)realloc(ret_corners, sizeof(xy)*rsize);
-        if(!ret_corners) return NULL;
+        xy* new_ret_corners = (xy*)realloc(ret_corners, sizeof(xy)*rsize);
+        if(!new_ret_corners)
+        {
+          free(ret_corners);
+          return NULL;
+        }
+        ret_corners = new_ret_corners;
       }
       ret_corners[num_corners].x = x;
       ret_corners[num_corners].y = y;