@@ -213,9 +213,12 @@ Credentials getCredentialsForItem(CFDictionaryRef item) {
213
213
CFDictionaryAddValue (query, kSecReturnData , kCFBooleanTrue );
214
214
CFDictionaryAddValue (query, kSecAttrAccount , account);
215
215
216
- CFTypeRef result;
216
+ Credentials cred;
217
+ CFTypeRef result = NULL ;
217
218
OSStatus status = SecItemCopyMatching ((CFDictionaryRef ) query, &result);
218
219
220
+ CFRelease (query);
221
+
219
222
if (status == errSecSuccess) {
220
223
CFDataRef passwordData = (CFDataRef ) CFDictionaryGetValue (
221
224
(CFDictionaryRef ) result,
@@ -225,15 +228,18 @@ Credentials getCredentialsForItem(CFDictionaryRef item) {
225
228
passwordData,
226
229
kCFStringEncodingUTF8 );
227
230
228
- Credentials cred = Credentials (
231
+ cred = Credentials (
229
232
CFStringToStdString (account),
230
233
CFStringToStdString (password));
234
+
231
235
CFRelease (password);
236
+ }
232
237
233
- return cred;
238
+ if (result != NULL ) {
239
+ CFRelease (result);
234
240
}
235
241
236
- return Credentials () ;
242
+ return cred ;
237
243
}
238
244
239
245
KEYTAR_OP_RESULT FindCredentials (const std::string& service,
@@ -255,9 +261,12 @@ KEYTAR_OP_RESULT FindCredentials(const std::string& service,
255
261
CFDictionaryAddValue (query, kSecReturnRef , kCFBooleanTrue );
256
262
CFDictionaryAddValue (query, kSecReturnAttributes , kCFBooleanTrue );
257
263
258
- CFTypeRef result;
264
+ CFTypeRef result = NULL ;
259
265
OSStatus status = SecItemCopyMatching ((CFDictionaryRef ) query, &result);
260
266
267
+ CFRelease (serviceStr);
268
+ CFRelease (query);
269
+
261
270
if (status == errSecSuccess) {
262
271
CFArrayRef resultArray = (CFArrayRef ) result;
263
272
int resultCount = CFArrayGetCount (resultArray);
@@ -277,13 +286,10 @@ KEYTAR_OP_RESULT FindCredentials(const std::string& service,
277
286
return FAIL_ERROR;
278
287
}
279
288
280
-
281
289
if (result != NULL ) {
282
290
CFRelease (result);
283
291
}
284
292
285
- CFRelease (query);
286
-
287
293
return SUCCESS;
288
294
}
289
295
0 commit comments