Skip to content

Commit 844c351

Browse files
author
Ahmad, Sameer
authored
Coverity high impact fixes (flame#107)
- Re-implemented memory leak fixes overwritten by LAPACKE update. - Implemented fixes for use of uninitialized variables in extreme cases. AMD-Internal: CPUPL-6488
1 parent 4fdb8fd commit 844c351

23 files changed

+172
-74
lines changed

src/base/flamec/wrappers/lapack/external/FLA_Chol_blk_external.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
99
*/
1010

11+
/*
12+
* Modifications Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
13+
*/
14+
1115
#include "FLAME.h"
1216

1317
FLA_Error FLA_Chol_blk_external( FLA_Uplo uplo, FLA_Obj A )
@@ -24,6 +28,7 @@ FLA_Error FLA_Chol_blk_external( FLA_Uplo uplo, FLA_Obj A )
2428

2529
if ( FLA_Obj_has_zero_dim( A ) ) return FLA_SUCCESS;
2630

31+
info = 0;
2732
datatype = FLA_Obj_datatype( A );
2833

2934
m_A = FLA_Obj_length( A );

src/base/flamec/wrappers/lapack/external/FLA_Chol_unb_external.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
99
*/
1010

11+
/*
12+
* Modifications Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
13+
*/
14+
1115
#include "FLAME.h"
1216

1317
FLA_Error FLA_Chol_unb_external( FLA_Uplo uplo, FLA_Obj A )
@@ -24,6 +28,7 @@ FLA_Error FLA_Chol_unb_external( FLA_Uplo uplo, FLA_Obj A )
2428

2529
if ( FLA_Obj_has_zero_dim( A ) ) return FLA_SUCCESS;
2630

31+
info = 0;
2732
datatype = FLA_Obj_datatype( A );
2833

2934
m_A = FLA_Obj_length( A );

src/base/flamec/wrappers/lapack/external/FLA_LU_piv_blk_external.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
99
*/
1010

11+
/*
12+
* Modifications Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
13+
*/
14+
1115
#include "FLAME.h"
1216

1317
FLA_Error FLA_LU_piv_blk_external( FLA_Obj A, FLA_Obj p )
@@ -23,6 +27,7 @@ FLA_Error FLA_LU_piv_blk_external( FLA_Obj A, FLA_Obj p )
2327

2428
if ( FLA_Obj_has_zero_dim( A ) ) return FLA_SUCCESS;
2529

30+
info = 0;
2631
datatype = FLA_Obj_datatype( A );
2732

2833
m_A = FLA_Obj_length( A );

src/base/flamec/wrappers/lapack/external/FLA_LU_piv_unb_external.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
99
*/
1010

11+
/*
12+
* Modifications Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
13+
*/
14+
1115
#include "FLAME.h"
1216

1317
FLA_Error FLA_LU_piv_unb_external( FLA_Obj A, FLA_Obj p )
@@ -23,6 +27,7 @@ FLA_Error FLA_LU_piv_unb_external( FLA_Obj A, FLA_Obj p )
2327

2428
if ( FLA_Obj_has_zero_dim( A ) ) return FLA_SUCCESS;
2529

30+
info = 0;
2631
datatype = FLA_Obj_datatype( A );
2732

2833
m_A = FLA_Obj_length( A );

src/base/flamec/wrappers/lapack/external/FLA_Trinv_blk_external.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
99
*/
1010

11+
/*
12+
* Modifications Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
13+
*/
14+
1115
#include "FLAME.h"
1216

1317
FLA_Error FLA_Trinv_blk_external( FLA_Uplo uplo, FLA_Diag diag, FLA_Obj A )
@@ -25,6 +29,7 @@ FLA_Error FLA_Trinv_blk_external( FLA_Uplo uplo, FLA_Diag diag, FLA_Obj A )
2529

2630
if ( FLA_Obj_has_zero_dim( A ) ) return FLA_SUCCESS;
2731

32+
info = 0;
2833
datatype = FLA_Obj_datatype( A );
2934

3035
m_A = FLA_Obj_length( A );

src/base/flamec/wrappers/lapack/external/FLA_Trinv_unb_external.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
99
*/
1010

11+
/*
12+
* Modifications Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
13+
*/
14+
1115
#include "FLAME.h"
1216

1317
FLA_Error FLA_Trinv_unb_external( FLA_Uplo uplo, FLA_Diag diag, FLA_Obj A )
@@ -25,6 +29,7 @@ FLA_Error FLA_Trinv_unb_external( FLA_Uplo uplo, FLA_Diag diag, FLA_Obj A )
2529

2630
if ( FLA_Obj_has_zero_dim( A ) ) return FLA_SUCCESS;
2731

32+
info = 0;
2833
datatype = FLA_Obj_datatype( A );
2934

3035
m_A = FLA_Obj_length( A );

src/lapacke/LAPACKE/src/lapacke_cgejsv.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
* Author: Intel Corporation
3131
*****************************************************************************/
3232

33+
/*
34+
* Modifications Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
35+
*/
36+
3337
#include "lapacke_utils.h"
3438

3539
lapack_int API_SUFFIX(LAPACKE_cgejsv)( int matrix_layout, char joba, char jobu, char jobv,
@@ -174,9 +178,9 @@ lapack_int API_SUFFIX(LAPACKE_cgejsv)( int matrix_layout, char joba, char jobu,
174178
istat[i] = iwork[i];
175179
}
176180
/* Release memory and exit */
177-
LAPACKE_free( cwork );
178-
exit_level_2:
179181
LAPACKE_free( rwork );
182+
exit_level_2:
183+
LAPACKE_free( cwork );
180184
exit_level_1:
181185
LAPACKE_free( iwork );
182186
exit_level_0:

src/lapacke/LAPACKE/src/lapacke_cgesvdq.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
* Author: Intel Corporation
3131
*****************************************************************************/
3232

33+
/*
34+
* Modifications Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
35+
*/
36+
3337
#include "lapacke_utils.h"
3438

3539
lapack_int API_SUFFIX(LAPACKE_cgesvdq)( int matrix_layout, char joba, char jobp,
@@ -80,22 +84,24 @@ lapack_int API_SUFFIX(LAPACKE_cgesvdq)( int matrix_layout, char joba, char jobp,
8084
cwork = (lapack_complex_float*)LAPACKE_malloc( sizeof(lapack_complex_float) * lcwork );
8185
if( cwork == NULL ) {
8286
info = LAPACK_WORK_MEMORY_ERROR;
83-
goto exit_level_0;
87+
goto exit_level_1;
8488
}
8589
rwork = (float*)LAPACKE_malloc( sizeof(float) * lrwork );
8690
if( rwork == NULL ) {
8791
info = LAPACK_WORK_MEMORY_ERROR;
88-
goto exit_level_0;
92+
goto exit_level_2;
8993
}
9094
/* Call middle-level interface */
9195
info = API_SUFFIX(LAPACKE_cgesvdq_work)( matrix_layout, joba, jobp, jobr, jobu, jobv,
9296
m, n, a, lda, s, u, ldu, v, ldv, numrank,
9397
iwork, liwork, cwork, lcwork, rwork, lrwork );
9498

9599
/* Release memory and exit */
96-
LAPACKE_free( iwork );
97-
LAPACKE_free( cwork );
98100
LAPACKE_free( rwork );
101+
exit_level_2:
102+
LAPACKE_free( cwork );
103+
exit_level_1:
104+
LAPACKE_free( iwork );
99105
exit_level_0:
100106
if( info == LAPACK_WORK_MEMORY_ERROR ) {
101107
API_SUFFIX(LAPACKE_xerbla)( "LAPACKE_cgesvdq", info );

src/lapacke/LAPACKE/src/lapacke_cgesvdx.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
* Author: Intel Corporation
3131
*****************************************************************************/
3232

33+
/*
34+
* Modifications Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
35+
*/
36+
3337
#include "lapacke_utils.h"
3438

3539
lapack_int API_SUFFIX(LAPACKE_cgesvdx)( int matrix_layout, char jobu, char jobvt, char range,
@@ -73,12 +77,12 @@ lapack_int API_SUFFIX(LAPACKE_cgesvdx)( int matrix_layout, char jobu, char jobvt
7377
LAPACKE_malloc( sizeof(lapack_complex_float) * lwork );
7478
if( work == NULL ) {
7579
info = LAPACK_WORK_MEMORY_ERROR;
76-
goto exit_level_1;
80+
goto exit_level_0;
7781
}
7882
rwork = (float*)LAPACKE_malloc( sizeof(float) * lrwork );
7983
if( rwork == NULL ) {
8084
info = LAPACK_WORK_MEMORY_ERROR;
81-
goto exit_level_0;
85+
goto exit_level_1;
8286
}
8387
iwork = (lapack_int*)LAPACKE_malloc( sizeof(lapack_int) * MAX(1,(12*MIN(m,n))) );
8488
if( iwork == NULL ) {
@@ -96,9 +100,9 @@ lapack_int API_SUFFIX(LAPACKE_cgesvdx)( int matrix_layout, char jobu, char jobvt
96100
/* Release memory and exit */
97101
LAPACKE_free( iwork );
98102
exit_level_2:
99-
LAPACKE_free( work );
100-
exit_level_1:
101103
LAPACKE_free( rwork );
104+
exit_level_1:
105+
LAPACKE_free( work );
102106
exit_level_0:
103107
if( info == LAPACK_WORK_MEMORY_ERROR ) {
104108
API_SUFFIX(LAPACKE_xerbla)( "LAPACKE_cgesvdx", info );

src/lapacke/LAPACKE/src/lapacke_chbevx_2stage_work.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
* Author: Intel Corporation
3131
*****************************************************************************/
3232

33+
/*
34+
* Modifications Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
35+
*/
36+
3337
#include "lapacke_utils.h"
3438

3539
lapack_int API_SUFFIX(LAPACKE_chbevx_2stage_work)( int matrix_layout, char jobz, char range,
@@ -105,9 +109,14 @@ lapack_int API_SUFFIX(LAPACKE_chbevx_2stage_work)( int matrix_layout, char jobz,
105109
}
106110
/* Query optimal working array(s) size if requested */
107111
if( lwork == -1 ) {
108-
LAPACK_chbevx_2stage( &jobz, &range, &uplo, &n, &kd, ab_t, &ldab_t, q_t,
112+
LAPACK_chbevx_2stage( &jobz, &range, &uplo, &n, &kd, ab_t, &ldab_t, q_t,
109113
&ldq_t, &vl, &vu, &il, &iu, &abstol, m, w, z_t, &ldz_t,
110114
work, &lwork, rwork, iwork, ifail, &info );
115+
LAPACKE_free( ab_t );
116+
if( LAPACKE_lsame( jobz, 'v' ) ) {
117+
LAPACKE_free( q_t );
118+
LAPACKE_free( z_t );
119+
}
111120
return (info < 0) ? (info - 1) : info;
112121
}
113122
/* Transpose input matrices */

0 commit comments

Comments
 (0)