AmendHub

Download (as of this amendment):

jcs

/

amend

/

amendments

/

185

*: Adapt to new xmalloc/xmalloczero

Also fix a memory leak in the latest repo migration

jcs made amendment 185 19 days ago
--- bile.c Mon Sep 28 13:51:53 2026 +++ bile.c Fri Oct 2 08:38:14 2026 @@ -71,7 +71,7 @@ bile_create(const Str255 filename, short vrefnum, cons return NULL; SetFPos(fh, fsFromStart, 0); - bile = xmalloczero(sizeof(struct bile)); + bile = xmalloc(sizeof(struct bile), M_ZERO); memcpy(bile->magic, BILE_MAGIC, sizeof(bile->magic)); bile->vrefnum = vrefnum; bile->frefnum = fh; @@ -100,7 +100,7 @@ bile_create(const Str255 filename, short vrefnum, cons /* padding */ len = BILE_HEADER_LEN - BILE_MAGIC_LEN - BILE_OBJECT_SIZE - BILE_OBJECT_SIZE; - tmp = xmalloczero(len); + tmp = xmalloc(len, M_ZERO); _bile_error = FSWrite(bile->frefnum, &len, tmp); if (_bile_error) goto create_bail; @@ -143,7 +143,7 @@ bile_open(const Str255 filename, short vrefnum) GetFPos(fh, &file_size); SetFPos(fh, fsFromStart, 0); - bile = xmalloczero(sizeof(struct bile)); + bile = xmalloc(sizeof(struct bile), M_ZERO); memcpy(bile->magic, BILE_MAGIC, sizeof(bile->magic)); bile->vrefnum = vrefnum; bile->frefnum = fh; @@ -275,7 +275,7 @@ bile_find(struct bile *bile, const OSType type, const if (o == NULL) return NULL; - ocopy = xmalloc(BILE_OBJECT_SIZE); + ocopy = xmalloc(BILE_OBJECT_SIZE, 0); memcpy(ocopy, o, BILE_OBJECT_SIZE); return ocopy; @@ -354,7 +354,7 @@ bile_get_nth_of_type(struct bile *bile, const unsigned continue; if (count == index) { - ocopy = xmalloc(BILE_OBJECT_SIZE); + ocopy = xmalloc(BILE_OBJECT_SIZE, 0); memcpy(ocopy, o, BILE_OBJECT_SIZE); return ocopy; } @@ -583,7 +583,7 @@ bile_read_alloc(struct bile *bile, const OSType type, return 0; } - *data = xmalloc(o->size); + *data = xmalloc(o->size, 0); ret = bile_read_object(bile, o, *data, o->size); return ret; @@ -685,7 +685,7 @@ iterate_fields: } if (!write) { - data = xmalloc(size); + data = xmalloc(size, 0); write = true; size = 0; goto iterate_fields; @@ -727,7 +727,7 @@ bile_unmarshall_object(struct bile *bile, memset(ptr, 0, sizeof(dptr)); continue; } - dptr = xmalloc(fsize); + dptr = xmalloc(fsize, 0); memcpy(ptr, &dptr, sizeof(dptr)); ptr = dptr; } @@ -891,7 +891,7 @@ bile_read_map(struct bile *bile, struct bile_object *m /* read entire map */ size = map_obj.size; - map = xmalloczero(size); + map = xmalloc(size, 0); _bile_error = FSRead(bile->frefnum, &size, map); if (_bile_error) { xfree(&map); --- browser.c Wed Sep 30 16:56:33 2026 +++ browser.c Fri Oct 2 08:22:40 2026 @@ -117,7 +117,7 @@ browser_init(struct repo *repo) Cell cell = { 0 }; short width, height; - browser = xmalloczero(sizeof(struct browser)); + browser = xmalloc(sizeof(struct browser), M_ZERO); browser->state = BROWSER_STATE_IDLE; browser->repo = repo; @@ -217,7 +217,7 @@ browser_init(struct repo *repo) TVSetScrollbar(browser->diff_tv, browser->diff_scroller); TVUpdateScrollbar(browser->diff_tv, browser->diff_scroller); - focusable = xmalloczero(sizeof(struct focusable)); + focusable = xmalloc(sizeof(struct focusable), M_ZERO); focusable->cookie = browser; focusable->win = browser->win; focusable->idle = browser_idle; --- committer.c Thu Oct 1 12:29:05 2026 +++ committer.c Fri Oct 2 08:23:27 2026 @@ -66,7 +66,7 @@ committer_init(struct browser *browser) TextStyle style; short fh; - committer = xmalloczero(sizeof(struct committer)); + committer = xmalloc(sizeof(struct committer), M_ZERO); committer->browser = browser; browser->committer = committer; @@ -149,7 +149,7 @@ committer_init(struct browser *browser) committer->log_focused = true; - focusable = xmalloczero(sizeof(struct focusable)); + focusable = xmalloc(sizeof(struct focusable), M_ZERO); focusable->cookie = committer; focusable->win = committer->win; focusable->modal = true; @@ -612,7 +612,7 @@ diff_output(const char *format, ...) panic("diff_output without committer_diffing"); if (committer_diffing->diff_line == NULL) { - committer_diffing->diff_line = xmalloc(DIFF_LINE_SIZE); + committer_diffing->diff_line = xmalloc(DIFF_LINE_SIZE, M_CANFAIL); if (committer_diffing->diff_line == NULL) { warn("Out of memory"); return 0; --- diffreg.c Mon Sep 28 16:50:34 2026 +++ diffreg.c Fri Oct 2 08:36:43 2026 @@ -187,7 +187,9 @@ static void unsort(struct line *, int, int *); static void change(char *, FILE *, char *, FILE *, int, int, int, int, int *); static void sort(struct line *, int); static void print_header(const char *, const char *); +#if 0 static int ignoreline(char *); +#endif static int asciifile(FILE *); static int fetch(long *, int, int, FILE *, int, int, int); static int newcand(int, int, int); @@ -887,7 +889,7 @@ preadline(int fd, size_t rlen, off_t off) ssize_t nr; off_t pos; - line = xmalloc(rlen + 1); + line = xmalloc(rlen + 1, 0); pos = lseek(fd, 0, SEEK_CUR); lseek(fd, off, SEEK_SET); if ((nr = read(fd, line, rlen)) == -1) @@ -899,18 +901,17 @@ preadline(int fd, size_t rlen, off_t off) return (line); } +#if 0 static int ignoreline(char *line) { -#if 0 int ret; ret = regexec(&ignore_re, line, 0, NULL, 0); xfree(&line); return (ret == 0); /* if it matched, it should be ignored. */ -#endif - return 0; } +#endif /* * Indicate that there is a difference between lines a and b of the from file @@ -929,6 +930,7 @@ restart: if (diff_format != D_IFDEF && a > b && c > d) return; if (ignore_pats != NULL) { +#if 0 char *line; /* * All lines in the change, insert, or delete must @@ -951,6 +953,9 @@ restart: goto proceed; } } +#else + panic("ignorelines not implemented (needs regexec)"); +#endif return; } proceed: --- editor.c Thu Oct 1 12:23:49 2026 +++ editor.c Fri Oct 2 08:24:04 2026 @@ -56,7 +56,7 @@ editor_init(struct browser *browser, struct repo_amend short fh, off; struct tm *ttm = NULL; - editor = xmalloczero(sizeof(struct editor)); + editor = xmalloc(sizeof(struct editor), M_ZERO); editor->browser = browser; editor->amendment = amendment; @@ -166,7 +166,7 @@ editor_init(struct browser *browser, struct repo_amend editor->last_te = editor->author_te; - focusable = xmalloczero(sizeof(struct focusable)); + focusable = xmalloc(sizeof(struct focusable), M_ZERO); focusable->cookie = editor; focusable->win = editor->win; focusable->modal = true; @@ -477,7 +477,7 @@ editor_save(struct editor *editor) return; } - date = xmalloc(len + 1); + date = xmalloc(len + 1, 0); memcpy(date, *(*(editor->date_te))->hText, len); date[len] = '\0'; --- repo.c Thu Oct 1 13:13:50 2026 +++ repo.c Fri Oct 2 17:47:17 2026 @@ -108,7 +108,7 @@ repo_init(struct bile *bile, bool is_new) unsigned long *ids; bool canceled = false; - repo = xmalloczero(sizeof(struct repo)); + repo = xmalloc(sizeof(struct repo), M_ZERO); repo->bile = bile; repo->next_file_id = 1; repo->next_amendment_id = 1; @@ -275,7 +275,7 @@ repo_parse_file(unsigned long id, unsigned char *data, datapos = 0; - file = xmalloczero(sizeof(struct repo_file)); + file = xmalloc(sizeof(struct repo_file), M_ZERO); file->id = id; /* filename, pstr */ @@ -321,7 +321,7 @@ repo_parse_amendment(unsigned long id, unsigned char * struct repo_amendment *amendment; unsigned short len, i; - amendment = xmalloczero(sizeof(struct repo_amendment)); + amendment = xmalloc(sizeof(struct repo_amendment), M_ZERO); amendment->id = id; /* date */ @@ -422,7 +422,7 @@ repo_diff_header(struct repo *repo, struct repo_amendm strlcpy(uname, amendment->author, sizeof(uname)); size = 256; - *ret = xmalloc(size + amendment->log_len + (ncrs * 2) + 2); + *ret = xmalloc(size + amendment->log_len + (ncrs * 2) + 2, 0); ttm = localtime(&amendment->date); header_len = snprintf(*ret, size, "Amendment: %d\r" @@ -477,7 +477,7 @@ repo_show_diff_text(struct repo *repo, struct repo_ame header_len = repo_diff_header(repo, amendment, &buf); all_len = header_len + diff_len; - dtext = xmalloc(all_len); + dtext = xmalloc(all_len, M_CANFAIL); if (dtext == NULL) { warn("Failed allocating %ld bytes for diff", all_len); return; @@ -597,8 +597,8 @@ repo_add_file(struct repo *repo) repo->nfiles++; repo->files = xrealloc(repo->files, repo->nfiles * sizeof(Ptr)); file = repo->files[repo->nfiles - 1] = - xmalloczero(sizeof(struct repo_file)); - + xmalloc(sizeof(struct repo_file), M_ZERO); + file->id = repo->next_file_id; repo->next_file_id++; memcpy(&file->filename, reply.fName + 1, reply.fName[0]); @@ -646,7 +646,7 @@ repo_file_update(struct repo *repo, struct repo_file * /* filename len, filename, type, creator, ctime, mtime, flags */ len = 1 + filename[0] + 4 + 4 + 4 + 4 + 1; - data = xmalloczero(len); + data = xmalloc(len, M_ZERO); datapos = 0; /* copy filename as pstr */ @@ -725,7 +725,7 @@ repo_checkout_file(struct repo *repo, struct repo_file } /* TODO: add offset to bile_read to read in chunks */ - text = xmalloc(textob->size); + text = xmalloc(textob->size, 0); size = bile_read_object(repo->bile, textob, text, textob->size); if (size != textob->size) panic("Failed to read text object %ld: %d", textob->id, @@ -1045,7 +1045,7 @@ repo_export_amendment(struct repo *repo, struct repo_a error); xfree(&buf); - buf = xmalloc(bob->size); + buf = xmalloc(bob->size, 0); size = bile_read_object(repo->bile, bob, buf, bob->size); error = FSWrite(frefnum, &size, buf); if (error) @@ -1070,7 +1070,7 @@ repo_amend(struct repo *repo, struct diffed_file *diff size_t fsize, size; short i, error, frefnum; - amendment = xmalloczero(sizeof(struct repo_amendment)); + amendment = xmalloc(sizeof(struct repo_amendment), M_ZERO); amendment->id = repo->next_amendment_id; amendment->date = Time; @@ -1154,7 +1154,7 @@ repo_amend(struct repo *repo, struct diffed_file *diff panic("Failed to get size of file %s: %d", PtoCstr(tfilename), error); - tdata = xmalloc(fsize); + tdata = xmalloc(fsize, 0); error = FSRead(frefnum, &fsize, tdata); if (error) panic("Failed to read %lu of file %s: %d", fsize, @@ -1218,7 +1218,7 @@ repo_marshall_amendment(struct repo_amendment *amendme /* author_email (pstr) */ len += 1 + strlen(amendment->author_email); - *retdata = xmalloc(len); + *retdata = xmalloc(len, 0); data = *retdata; data[pos++] = (amendment->date >> 24) & 0xff; @@ -1377,7 +1377,7 @@ repo_migrate(struct repo *repo, bool is_new) char *data, *retdata; unsigned long *ids; bool bad; - + namendments = bile_sorted_ids_by_type(repo->bile, REPO_AMENDMENT_RTYPE, &ids); @@ -1410,9 +1410,14 @@ repo_migrate(struct repo *repo, bool is_new) repo_marshall_amendment(amendment, &retdata, &retsize); bile_write(repo->bile, REPO_AMENDMENT_RTYPE, ids[i], retdata, retsize); + xfree(&retdata); + if (amendment->log) + DisposeHandle(amendment->log); + if (amendment->file_ids != NULL) + xfree(&amendment->file_ids); + xfree(&amendment); - xfree(&retdata); } xfree(&ids);