Skip to content

Commit 36d196c

Browse files
committed
Memory fixes and turn off asan
Fixed another memory leak, got rid of free_bookmarks() because I can just use nob_da_free(). Turned address sanitizer back off because I don't know how to fix the last two memory leaks.
1 parent 22accea commit 36d196c

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

nob.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ bool build_wdc_lib(Nob_Cmd *cmd) {
2222
nob_da_free(source_paths);
2323
return true;
2424
}
25-
nob_cmd_append(cmd, "cc", "-Wall", "-Wextra","-fsanitize=address", "-g", "-c", src_path, "-o", bin_path);
25+
/* nob_cmd_append(cmd, "cc", "-Wall", "-Wextra","-fsanitize=address", "-g", "-c", src_path, "-o", bin_path); */
26+
nob_cmd_append(cmd, "cc", "-Wall", "-Wextra", "-g", "-c", src_path, "-o", bin_path);
2627
if (!nob_cmd_run_sync_and_reset(cmd)) return false;
2728
/* Create static lib */
2829
nob_cmd_append(cmd, "ar", "rcs", BUILD_FOLDER"libwdc.a", bin_path);
@@ -47,7 +48,8 @@ bool build_wdc_main(Nob_Cmd *cmd) {
4748
return true;
4849
}
4950
/* Link static library with main */
50-
nob_cmd_append(cmd, "cc", "-Wall", "-Wextra", "-fsanitize=address", "-g", src_path, "-o", bin_path, "-L"BUILD_FOLDER, "-lwdc");
51+
/* nob_cmd_append(cmd, "cc", "-Wall", "-Wextra", "-fsanitize=address", "-g", src_path, "-o", bin_path, "-L"BUILD_FOLDER, "-lwdc"); */
52+
nob_cmd_append(cmd, "cc", "-Wall", "-Wextra", "-g", src_path, "-o", bin_path, "-L"BUILD_FOLDER, "-lwdc");
5153
if (!nob_cmd_run_sync_and_reset(cmd)) return false;
5254
nob_da_free(source_paths);
5355
return true;
@@ -59,7 +61,8 @@ bool build_and_run_test(Nob_Cmd *cmd, const char *test_name) {
5961
const char *src_path = nob_temp_sprintf("%s%s.c", TESTS_FOLDER, test_name);
6062

6163
build_wdc_lib(cmd);
62-
nob_cmd_append(cmd, "cc", "-Wall", "-Wextra", "-fsanitize=address", "-g", src_path, "-o", bin_path, "-L"BUILD_FOLDER, "-lwdc");
64+
/* nob_cmd_append(cmd, "cc", "-Wall", "-Wextra", "-fsanitize=address", "-g", src_path, "-o", bin_path, "-L"BUILD_FOLDER, "-lwdc"); */
65+
nob_cmd_append(cmd, "cc", "-Wall", "-Wextra", "-g", src_path, "-o", bin_path, "-L"BUILD_FOLDER, "-lwdc");
6366
if (!nob_cmd_run_sync_and_reset(cmd)) return false;
6467
nob_cmd_append(cmd, bin_path);
6568
if (!nob_cmd_run_sync_and_reset(cmd)) return false;

src/wdc.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,6 @@ Bookmarks get_bookmarks(void) {
111111
return bookmarks;
112112
}
113113

114-
int free_bookmarks(Bookmarks bookmarks) {
115-
for (size_t i = 0; i < bookmarks.count; i++) {
116-
nob_sb_free(bookmarks.items[i]);
117-
}
118-
return 0;
119-
}
120-
121114
/**
122115
* @brief Get bookmarks in reverse order
123116
*
@@ -166,7 +159,7 @@ int list_bookmarks(void) {
166159
* @details Pop the top bookmark and write the rest back to the file.
167160
* @return The bookmark path
168161
*/
169-
const char *pop(void) {
162+
char *pop(void) {
170163
Bookmarks bookmarks = get_bookmarks_reversed();
171164
char *popped_path = NULL;
172165
if (bookmarks.items == NULL || bookmarks.count == 0) {
@@ -188,8 +181,8 @@ const char *pop(void) {
188181
int result = nob_write_entire_file(bookmark_path.items, bookmarks_sb.items, bookmarks_sb.count);
189182
popped_path = strndup(bm_sv.data, bm_sv.count);
190183
nob_sb_free(bookmark_path);
191-
nob_da_free(bookmarks);
192184
nob_sb_free(bookmarks_sb);
185+
nob_da_free(bookmarks);
193186
if (!result) {
194187
return NULL;
195188
}

src/wdc.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ FILE *open_bookmark_file(const char *mode);
1919
void add_to_file(const char *name, const char *cwd_path, FILE *bookmark_file);
2020
int add(const char *name);
2121
Bookmarks get_bookmarks(void);
22-
int free_bookmarks(Bookmarks bookmarks);
2322
Bookmarks get_bookmarks_reversed(void);
2423
int list_bookmarks(void);
2524
char *find(const char *name);
26-
const char *pop(void);
25+
char *pop(void);
2726

2827
#endif

tests/test_add_and_get_bookmarks.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ TEST add_should_add_to_file(void) {
1515
printf("bookmark: %s\n", bms.items[0].items);
1616
rmdir(temp_path);
1717
nob_temp_rewind(mark);
18-
free_bookmarks(bms);
18+
nob_da_free(bms);
1919
PASS();
2020
}
2121

@@ -29,10 +29,11 @@ TEST pop_should_pop_entry(void) {
2929
// Add again so there's two
3030
ASSERT_EQ(0, add("test"));
3131
ASSERT_EQ(0, add("test"));
32-
const char *bm = pop();
32+
char *bm = pop();
3333
printf("pop path: %s\n", temp_path);
3434
printf("*bm: %s\n", bm);
3535
// TODO: assert on something
36+
free(bm);
3637
rmdir(temp_path);
3738
nob_temp_rewind(mark);
3839
PASS();

0 commit comments

Comments
 (0)