Permalink
Browse files

Merge pull request #21 from appden/master

Fix potential memory leak in SUUIDModelHash
  • Loading branch information...
Matt Massicotte
Matt Massicotte committed Sep 26, 2012
2 parents e57510c + d0a268a commit 2ab3f2938e6cc423c2215c493509c8885836c72d
Showing with 6 additions and 14 deletions.
  1. +6 −14 SecureUDID.m
View
@@ -256,23 +256,17 @@ Applies the operation (encrypt or decrypt) to the NSData value with the provided
NSData* SUUIDModelHash(void) {
NSString* result;
- result = @"Unknown";
+ result = nil;
do {
size_t size;
- char* value;
-
- value = NULL;
// first get the size
if (sysctlbyname("hw.machine", NULL, &size, NULL, 0) != 0) {
break;
}
- value = malloc(size);
- if (!value) {
- break;
- }
+ char value[size];
// now get the value
if (sysctlbyname("hw.machine", value, &size, NULL, 0) != 0) {
@@ -281,14 +275,12 @@ Applies the operation (encrypt or decrypt) to the NSData value with the provided
// convert the value to an NSString
result = [NSString stringWithCString:value encoding:NSUTF8StringEncoding];
- if (!result) {
- break;
- }
-
- // free our buffer
- free(value);
} while (0);
+ if (!result) {
+ result = @"Unknown";
+ }
+
return SUUIDHash([result dataUsingEncoding:NSUTF8StringEncoding]);
}

0 comments on commit 2ab3f29

Please sign in to comment.