fix: fixed segfault
							parent
							
								
									a153c4e22d
								
							
						
					
					
						commit
						01eb5ece55
					
				
							
								
								
									
										5
									
								
								Makefile
								
								
								
								
							
							
						
						
									
										5
									
								
								Makefile
								
								
								
								
							|  | @ -43,6 +43,11 @@ prod: cmake-release | |||
| run: build | ||||
| 	@ LANDER_DATA_DIR=data LANDER_BASE_URL=http://localhost:18080/ LANDER_API_KEY=test ./build/Debug/lander | ||||
| 
 | ||||
| .PHONY: valgrind | ||||
| valgrind: build | ||||
| 	@ LANDER_DATA_DIR=data LANDER_BASE_URL=http://localhost:18080/ LANDER_API_KEY=test \
 | ||||
| 		valgrind --tool=memcheck --error-exitcode=1 --track-origins=yes --leak-check=full ./build/Debug/lander | ||||
| 
 | ||||
| .PHONY: gdb | ||||
| gdb: build | ||||
| 	@ LANDER_DATA_DIR=data LANDER_BASE_URL=http://localhost:18080/ LANDER_API_KEY=test gdb --args ./build/Debug/lander | ||||
|  |  | |||
|  | @ -28,10 +28,9 @@ TrieExitCode trie_init(Trie **trie_ptr, const char *file_path) { | |||
|   trie->root = tnode_init(); | ||||
|   pthread_rwlock_init(&trie->lock, NULL); | ||||
| 
 | ||||
|   *trie_ptr = trie; | ||||
| 
 | ||||
|   if (file_path == NULL) { | ||||
|     trie->file_path = NULL; | ||||
|     *trie_ptr = trie; | ||||
|     return Ok; | ||||
|   } | ||||
| 
 | ||||
|  | @ -50,7 +49,7 @@ TrieExitCode trie_init(Trie **trie_ptr, const char *file_path) { | |||
|   Entry *entry; | ||||
|   char *string; | ||||
|   int i, j; | ||||
|   int entries = 0; | ||||
|   TrieExitCode status; | ||||
| 
 | ||||
|   while (fgets(buffer, 8192, fp)) { | ||||
|     i = 0; | ||||
|  | @ -76,13 +75,18 @@ TrieExitCode trie_init(Trie **trie_ptr, const char *file_path) { | |||
|     buffer[j] = '\0'; | ||||
| 
 | ||||
|     entry = entry_new(type, buffer + i + 3); | ||||
|     trie_add_no_lock(trie, buffer, entry); | ||||
|     status = trie_add_no_lock(trie, buffer, entry); | ||||
| 
 | ||||
|     entries++; | ||||
|     if (status != Ok) { | ||||
|       trie_free(trie); | ||||
|       return status; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   fclose(fp); | ||||
| 
 | ||||
|   *trie_ptr = trie; | ||||
| 
 | ||||
|   return Ok; | ||||
| } | ||||
| 
 | ||||
|  | @ -266,6 +270,7 @@ TrieExitCode trie_add_no_lock(Trie *trie, const char *string, Entry *entry) { | |||
|   } | ||||
| 
 | ||||
|   (*child_node_ptr)->represents = true; | ||||
|   (*child_node_ptr)->entry = entry; | ||||
|   trie->size++; | ||||
|   return Ok; | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue