avutil/pca: Check for av_malloc* failures
authorMichael Niedermayer <michaelni@gmx.at>
Mon, 30 Mar 2015 02:37:42 +0000 (04:37 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Wed, 22 Apr 2015 10:27:24 +0000 (12:27 +0200)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit dadc43eee4d9036aa532665a04720238cc15e922)

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavutil/pca.c

index 311b6bc..a745136 100644 (file)
@@ -41,12 +41,20 @@ PCA *ff_pca_init(int n){
         return NULL;
 
     pca= av_mallocz(sizeof(*pca));
+    if (!pca)
+        return NULL;
+
     pca->n= n;
     pca->z = av_malloc(sizeof(*pca->z) * n);
     pca->count=0;
     pca->covariance= av_calloc(n*n, sizeof(double));
     pca->mean= av_calloc(n, sizeof(double));
 
+    if (!pca->z || !pca->covariance || !pca->mean) {
+        ff_pca_free(pca);
+        return NULL;
+    }
+
     return pca;
 }