Prevent memory leak in fuzzer
This commit is contained in:
		| @@ -9,7 +9,7 @@ | |||||||
| char *get_null_terminated(const uint8_t *data, size_t size) { | char *get_null_terminated(const uint8_t *data, size_t size) { | ||||||
|     char *new_str = (char *)malloc(size+1); |     char *new_str = (char *)malloc(size+1); | ||||||
|     if (new_str == NULL){ |     if (new_str == NULL){ | ||||||
|             return NULL; | 	exit(1); | ||||||
|     } |     } | ||||||
|     memcpy(new_str, data, size); |     memcpy(new_str, data, size); | ||||||
|     new_str[size] = '\0'; |     new_str[size] = '\0'; | ||||||
| @@ -57,18 +57,20 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size){ | |||||||
|     sprintf(filename, "/tmp/libfuzzer.%d", getpid()); |     sprintf(filename, "/tmp/libfuzzer.%d", getpid()); | ||||||
|  |  | ||||||
|     FILE *fp = fopen(filename, "wb"); |     FILE *fp = fopen(filename, "wb"); | ||||||
|     if (!fp) { |     if (fp) { | ||||||
|             return 0; |  | ||||||
|     } |  | ||||||
| 	fwrite(data, size, 1, fp); | 	fwrite(data, size, 1, fp); | ||||||
| 	fclose(fp); | 	fclose(fp); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     FILE *f = fopen(filename, "r"); |     FILE *f = fopen(filename, "r"); | ||||||
|  |     if (f) { | ||||||
| 	Str s = Strfgetall(f); | 	Str s = Strfgetall(f); | ||||||
| 	wc_Str_conv_with_detect(s, &from, from, to); | 	wc_Str_conv_with_detect(s, &from, from, to); | ||||||
| 	if (s != NULL) { | 	if (s != NULL) { | ||||||
| 	    Strfree(s); | 	    Strfree(s); | ||||||
| 	} | 	} | ||||||
|  | 	fclose(f); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     unlink(filename); |     unlink(filename); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user