mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-30 18:17:55 +00:00 
			
		
		
		
	Release database resources on each iteration of a loop (#4305)
This commit is contained in:
		| @@ -10,6 +10,7 @@ import ( | ||||
| 	stdmysql "github.com/go-sql-driver/mysql" | ||||
| 	"github.com/hashicorp/vault/api" | ||||
| 	"github.com/hashicorp/vault/builtin/logical/database/dbplugin" | ||||
| 	"github.com/hashicorp/vault/helper/dbtxn" | ||||
| 	"github.com/hashicorp/vault/helper/strutil" | ||||
| 	"github.com/hashicorp/vault/plugins" | ||||
| 	"github.com/hashicorp/vault/plugins/helper/database/connutil" | ||||
| @@ -182,10 +183,11 @@ func (m *MySQL) CreateUser(ctx context.Context, statements dbplugin.Statements, | ||||
|  | ||||
| 				return "", "", err | ||||
| 			} | ||||
| 			defer stmt.Close() | ||||
| 			if _, err := stmt.ExecContext(ctx); err != nil { | ||||
| 				stmt.Close() | ||||
| 				return "", "", err | ||||
| 			} | ||||
| 			stmt.Close() | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| @@ -291,16 +293,12 @@ func (m *MySQL) RotateRootCredentials(ctx context.Context, statements []string) | ||||
| 			if len(query) == 0 { | ||||
| 				continue | ||||
| 			} | ||||
| 			stmt, err := tx.PrepareContext(ctx, dbutil.QueryHelper(query, map[string]string{ | ||||
|  | ||||
| 			m := map[string]string{ | ||||
| 				"username": m.Username, | ||||
| 				"password": password, | ||||
| 			})) | ||||
| 			if err != nil { | ||||
| 				return nil, err | ||||
| 			} | ||||
|  | ||||
| 			defer stmt.Close() | ||||
| 			if _, err := stmt.ExecContext(ctx); err != nil { | ||||
| 			if err := dbtxn.ExecuteTxQuery(ctx, tx, m, query); err != nil { | ||||
| 				return nil, err | ||||
| 			} | ||||
| 		} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Becca Petrin
					Becca Petrin