| 
									
										
										
										
											2016-05-18 02:20:24 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2017-04-10 08:05:55 +08:00
										 |  |  |  * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2016-01-08 04:06:38 +08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2016-05-18 02:20:24 +08:00
										 |  |  |  * Licensed under the OpenSSL license (the "License").  You may not use | 
					
						
							|  |  |  |  * this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  |  * in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							| 
									
										
										
										
											2016-01-08 04:06:38 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <openssl/bio.h>
 | 
					
						
							|  |  |  | #include <openssl/crypto.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-10 08:05:55 +08:00
										 |  |  | #include "testutil.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * We use a proper main function here instead of the custom main from the | 
					
						
							|  |  |  |  * test framework because the CRYPTO_mem_leaks_fp function cannot be called | 
					
						
							|  |  |  |  * a second time without trying to use a null pointer.  The test framework | 
					
						
							|  |  |  |  * calls this function as part of its close down. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * A work around is to call putenv("OPENSSL_DEBUG_MEMORY=0"); before exiting | 
					
						
							|  |  |  |  * but that is worse than avoiding the test framework's main. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int main(int argc, char *argv[]) | 
					
						
							| 
									
										
										
										
											2016-01-08 04:06:38 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-11 03:42:10 +08:00
										 |  |  | #ifndef OPENSSL_NO_CRYPTO_MDEBUG
 | 
					
						
							| 
									
										
										
										
											2016-01-08 04:06:38 +08:00
										 |  |  |     char *p; | 
					
						
							|  |  |  |     char *lost; | 
					
						
							| 
									
										
										
										
											2016-01-11 07:29:46 +08:00
										 |  |  |     int noleak; | 
					
						
							| 
									
										
										
										
											2016-01-08 04:06:38 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     p = getenv("OPENSSL_DEBUG_MEMORY"); | 
					
						
							|  |  |  |     if (p != NULL && strcmp(p, "on") == 0) | 
					
						
							|  |  |  |         CRYPTO_set_mem_debug(1); | 
					
						
							|  |  |  |     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     lost = OPENSSL_malloc(3); | 
					
						
							| 
									
										
										
										
											2017-04-10 08:05:55 +08:00
										 |  |  |     if (!TEST_ptr(lost)) | 
					
						
							|  |  |  |         return EXIT_FAILURE; | 
					
						
							| 
									
										
										
										
											2016-01-08 04:06:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-11 03:42:10 +08:00
										 |  |  |     if (argv[1] && strcmp(argv[1], "freeit") == 0) { | 
					
						
							| 
									
										
										
										
											2016-01-08 04:06:38 +08:00
										 |  |  |         OPENSSL_free(lost); | 
					
						
							| 
									
										
										
										
											2016-01-11 03:42:10 +08:00
										 |  |  |         lost = NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-01-08 04:06:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-11 07:29:46 +08:00
										 |  |  |     noleak = CRYPTO_mem_leaks_fp(stderr); | 
					
						
							|  |  |  |     /* If -1 return value something bad happened */ | 
					
						
							| 
									
										
										
										
											2017-04-10 08:05:55 +08:00
										 |  |  |     if (!TEST_int_ne(noleak, -1)) | 
					
						
							|  |  |  |         return EXIT_FAILURE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return TEST_int_eq(lost != NULL, noleak == 0) ? EXIT_SUCCESS : EXIT_FAILURE; | 
					
						
							| 
									
										
										
										
											2016-01-08 04:06:38 +08:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2017-04-10 08:05:55 +08:00
										 |  |  |     return EXIT_SUCCESS; | 
					
						
							| 
									
										
										
										
											2016-01-08 04:06:38 +08:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | } |