Some cleanups
cover Some cleanups
One of my first patches to Git were cleanup patches, and I fell back to my old pattern here, while thinking on how to write better commit messages for the submodule bugfixes I currently have in flight.
Just some one liners to not leak memory or file descriptors.
They are bundled as a series, but no patch relies on any predessor.
This applies on v2.8.0.
Thanks,
Stefan
Stefan Beller (6):
path.c: allocate enough memory for string
imap-send.c, cram: allocate enough memory for null terminated string
notes: don't leak memory in git_config_get_notes_strategy
abbrev_sha1_in_line: don't leak memory
bundle: don't leak an fd in case of early return credential-cache, send_request: close fd when done
builtin/notes.c | 1 + bundle.c | 10 ++++++++-- credential-cache.c | 1 + imap-send.c | 2 +- path.c | 2 +- wt-status.c | 2 +- 6 files changed, 13 insertions(+), 5 deletions(-)
Signature · 1 line
2.8.0.8.g27a27a6.dirty
PATCH 1/6 path.c: allocate enough memory for string
strlen returns the length of a string without the terminating null byte. To make sure enough memory is allocated we need to pass strlen(..) + 1 to the allocation function.
--- path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
path.c +1 -1
@@ -155,7 +155,7 @@ static struct trie *make_trie_node(const char *key, void *value)struct trie *new_node =xcalloc (1 ,sizeof (*new_node)); new_node->len =strlen (key);if (new_node->len) { - new_node->contents =xmalloc (new_node->len); + new_node->contents =xmalloc (new_node->len +1 );memcpy (new_node->contents, key, new_node->len); } new_node->value = value;
Signature · 1 line
2.8.0.8.g27a27a6.dirty
Re: [PATCH 1/6] path.c: allocate enough memory for string
Quoted 8 lines · Stefan Beller
strlenreturns the length of a string without the terminating null byte. To make sure enough memory is allocated we need to passstrlen(..) + 1to the allocation function.Signed-off-by Stefan Beller <[email protected]>---
path.c static struct trie *make_trie_node(const char *key, void *value) · line 159
Quoted 6 lines
path.c +1
-1@@ -155,7 +155,7 @@ static struct trie *make_trie_node(const char *key, void *value)struct trie *new_node =xcalloc (1 ,sizeof (*new_node)); new_node->len =strlen (key);if (new_node->len) { - new_node->contents =xmalloc (new_node->len); + new_node->contents =xmalloc (new_node->len +1 );memcpy (new_node->contents, key, new_node->len);
Huh? This is a trie. It never accesses 'contents' as a NUL-terminated string. Plus, no NUL is ever even copied, thus this is just overallocating. How is this an improvement?
Quoted 3 lines
path.c +0
-1} new_node->value = value; --
Re: [PATCH 1/6] path.c: allocate enough memory for string
In reply to Stefan BellerQuoted 14 lines · Stefan Beller
strlenreturns the length of a string without the terminating null byte. To make sure enough memory is allocated we need to passstrlen(..) + 1to the allocation function.Signed-off-by Stefan Beller <[email protected]>--- path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)path.c +0
-0
path.c static struct trie *make_trie_node(const char *key, void *value) · line 160
Quoted 7 lines
path.c +1
-1@@ -155,7 +155,7 @@ static struct trie *make_trie_node(const char *key, void *value)struct trie *new_node =xcalloc (1 ,sizeof (*new_node)); new_node->len =strlen (key);if (new_node->len) { - new_node->contents =xmalloc (new_node->len); + new_node->contents =xmalloc (new_node->len +1 );memcpy (new_node->contents, key, new_node->len); }
This structure looks like a counted string <len,ptr> that does not want to have a terminating NUL after the contents, judging from the way memcpy() copies only len and not len+1.
Did I write this (wondering why this was addressed to me)?
Quoted 1 line
path.c +0
-0new_node->value = value;
PATCH 2/6 imap-send.c, cram: allocate enough memory for null terminated string
In reply to Stefan Bellerstrlen returns the length of a string without the terminating null byte. To make sure enough memory is allocated we need to pass strlen(..) + 1 to the allocation function.
--- imap-send.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
imap-send.c +1 -1
@@ -872,7 +872,7 @@ static char *cram(const char *challenge_64, const char *user, const char *pass)* enough upper bound for challenge (decoded result). */ encoded_len =strlen (challenge_64); - challenge =xmalloc (encoded_len); + challenge =xmalloc (encoded_len +1 ); decoded_len =EVP_DecodeBlock ((unsigned char *)challenge, (unsigned char *)challenge_64, encoded_len);if (decoded_len <0 )
Signature · 1 line
2.8.0.8.g27a27a6.dirty
Re: [PATCH 2/6] imap-send.c, cram: allocate enough memory for null terminated string
Quoted 14 lines · Stefan Beller
strlenreturns the length of a string without the terminating null byte. To make sure enough memory is allocated we need to passstrlen(..) + 1to the allocation function.Signed-off-by Stefan Beller <[email protected]>--- imap-send.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)imap-send.c +0
-0
imap-send.c static char *cram(const char *challenge_64, const char *user, const char *pass) · line 878
Quoted 8 lines
imap-send.c +1
-1@@ -872,7 +872,7 @@ static char *cram(const char *challenge_64, const char *user, const char *pass)* enough upper bound for challenge (decoded result). */ encoded_len =strlen (challenge_64); - challenge =xmalloc (encoded_len); + challenge =xmalloc (encoded_len +1 ); decoded_len =EVP_DecodeBlock ((unsigned char *)challenge, (unsigned char *)challenge_64, encoded_len);if (decoded_len <0 )
Others pointed out that patches 1 and 2 here probably don't need the extra byte. But as a side note, for any cases that do, please use xmallocz() instead of manually adding 1 to the length. Even if you don't need the final byte to be NUL, it checks for integer overflow.
-Peff
Re: [PATCH 2/6] imap-send.c, cram: allocate enough memory for null terminated string
In reply to Stefan BellerQuoted 14 lines · Stefan Beller
strlenreturns the length of a string without the terminating null byte. To make sure enough memory is allocated we need to passstrlen(..) + 1to the allocation function.Signed-off-by Stefan Beller <[email protected]>--- imap-send.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)imap-send.c +0
-0
imap-send.c static char *cram(const char *challenge_64, const char *user, const char *pass) · line 875
Quoted 5 lines
imap-send.c +1
-1@@ -872,7 +872,7 @@ static char *cram(const char *challenge_64, const char *user, const char *pass)* enough upper bound for challenge (decoded result). */ encoded_len =strlen (challenge_64); - challenge =xmalloc (encoded_len); + challenge =xmalloc (encoded_len +1 );
'challenge' is never used as a NUL-terminated string, and EVP_DecodeBlock() is not advertised as adding a terminating NUL, so why is this an improvement?
Quoted 4 lines
imap-send.c +0
-1decoded_len =EVP_DecodeBlock ((unsigned char *)challenge, (unsigned char *)challenge_64, encoded_len);if (decoded_len <0 ) --
PATCH 3/6 notes: don't leak memory in git_config_get_notes_strategy
In reply to Stefan Bellervalue is just a temporary scratchpad, so we need to make sure it doesn't leak. It is xstrdup'd in git_config_get_string_const and parse_notes_merge_strategy just compares the string against predefined values, so no need to keep it around longer.
--- builtin/notes.c | 1 + 1 file changed, 1 insertion(+)
builtin/notes.c +1 -0
@@ -751,6 +751,7 @@ static int git_config_get_notes_strategy(const char *key,if (parse_notes_merge_strategy (value, strategy))git_die_config (key,"unknown notes merge strategy %s" , value); +free ((void *)value);return 0 ; }
Signature · 1 line
2.8.0.8.g27a27a6.dirty
Re: [PATCH 3/6] notes: don't leak memory in git_config_get_notes_strategy
Quoted 15 lines · Stefan Beller
valueis just a temporary scratchpad, so we need to make sure it doesn't leak. It is xstrdup'd ingit_config_get_string_constandparse_notes_merge_strategyjust compares the string against predefined values, so no need to keep it around longer.Signed-off-by Stefan Beller <[email protected]>--- builtin/notes.c | 1 + 1 file changed, 1 insertion(+)builtin/notes.c +0
-0
builtin/notes.c static int git_config_get_notes_strategy(const char *key, · line 756
Quoted 6 lines
builtin/notes.c +1
-0@@ -751,6 +751,7 @@ static int git_config_get_notes_strategy(const char *key,if (parse_notes_merge_strategy (value, strategy))git_die_config (key,"unknown notes merge strategy %s" , value); +free ((void *)value);return 0 ; }
I don't think this is wrong, but would it perhaps be simpler to call git_config_get_value() in the first place, which does not make a copy of the string?
-Peff
Re: [PATCH 3/6] notes: don't leak memory in git_config_get_notes_strategy
In reply to Stefan Bellerbuiltin/notes.c static int git_config_get_notes_strategy(const char *key, · line 754
Quoted 13 lines · Stefan Beller
valueis just a temporary scratchpad, so we need to make sure it doesn't leak. It is xstrdup'd ingit_config_get_string_constandparse_notes_merge_strategyjust compares the string against predefined values, so no need to keep it around longer.Signed-off-by Stefan Beller <[email protected]>---
builtin/notes.c +1
-0@@ -751,6 +751,7 @@ static int git_config_get_notes_strategy(const char *key,if (parse_notes_merge_strategy (value, strategy))git_die_config (key,"unknown notes merge strategy %s" , value); +free ((void *)value);
I wonder if the intent would be clearer if you gave 'value' type 'char *' rather than 'const char *', and called git_config_get_string() rather than git_config_get_string_const().
Quoted 2 lines
builtin/notes.c +0
-0return 0 ; }
PATCH 4/6 abbrev_sha1_in_line: don't leak memory
In reply to Stefan Bellersplit is of type struct strbuf ** and just before the new free, we release the inner strbufs. Make sure to also release the memory containing the pointers to the individual strbufs.
--- wt-status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
wt-status.c +1 -1
@@ -1065,7 +1065,7 @@ static void abbrev_sha1_in_line(struct strbuf *line) }for (i =0 ; split[i]; i++)strbuf_release (split[i]); - +free (split); }static void read_rebase_todolist (const char *fname,struct string_list *lines)
Signature · 1 line
2.8.0.8.g27a27a6.dirty
Re: [PATCH 4/6] abbrev_sha1_in_line: don't leak memory
Quoted 14 lines · Stefan Beller
splitis of typestruct strbuf **and just before the new free, we release the inner strbufs. Make sure to also release the memory containing the pointers to the individual strbufs.Signed-off-by Stefan Beller <[email protected]>--- wt-status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)wt-status.c +0
-0
wt-status.c static void abbrev_sha1_in_line(struct strbuf *line) · line 1069
Quoted 6 lines
wt-status.c +1
-1@@ -1065,7 +1065,7 @@ static void abbrev_sha1_in_line(struct strbuf *line) }for (i =0 ; split[i]; i++)strbuf_release (split[i]); - +free (split); }
I think this can just combine with the for-loop above to become strbuf_list_free().
-Peff
Re: [PATCH 4/6] abbrev_sha1_in_line: don't leak memory
Quoted 5 lines · Jeff King
Quoted 4 lines · Stefan Beller
splitis of typestruct strbuf **and just before the new free, we release the inner strbufs. Make sure to also release the memory containing the pointers to the individual strbufs.
Quoted 13 lines
wt-status.c static void abbrev_sha1_in_line(struct strbuf *line) · line 1069
Quoted 10 lines
Signed-off-by Stefan Beller <[email protected]>---
wt-status.c +1
-1@@ -1065,7 +1065,7 @@ static void abbrev_sha1_in_line(struct strbuf *line) }for (i =0 ; split[i]; i++)strbuf_release (split[i]); - +free (split); }I think this can just combine with the for-loop above to become
strbuf_list_free().
The implementation of strbuf_list_free() is this:
struct strbuf **s = sbs;
while (*s) {
strbuf_release(*s);
free(*s++);
}
free(sbs);which means that wt-status.c is leaking not only 'split', but also each element of split[], right?
Re: [PATCH 4/6] abbrev_sha1_in_line: don't leak memory
Quoted 29 lines · Eric Sunshine
Quoted 5 lines · Jeff King
Quoted 4 lines · Stefan Beller
splitis of typestruct strbuf **and just before the new free, we release the inner strbufs. Make sure to also release the memory containing the pointers to the individual strbufs.Quoted 13 lines
wt-status.c static void abbrev_sha1_in_line(struct strbuf *line) · line 1069
Quoted 10 lines
Signed-off-by Stefan Beller <[email protected]>---
wt-status.c +1
-1@@ -1065,7 +1065,7 @@ static void abbrev_sha1_in_line(struct strbuf *line) }for (i =0 ; split[i]; i++)strbuf_release (split[i]); - +free (split); }I think this can just combine with the for-loop above to become
strbuf_list_free().The implementation of
strbuf_list_free()is this:struct strbuf **s = sbs; while (*s) { strbuf_release(*s); free(*s++); } free(sbs);
Quoted 2 lines
which means that
wt-status.cis leaking not only 'split', but also each element of split[], right?
Yeah, I didn't notice that, but I think you're right.
-Peff
PATCH 5/6 bundle: don't leak an fd in case of early return
In reply to Stefan BellerIn successful operation write_pack_data will close the bundle_fd, but when we exit early, we need to take care of the file descriptor ourselves.
--- bundle.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
bundle.c +8 -2
@@ -434,8 +434,11 @@ int create_bundle(struct bundle_header *header, const char *path,init_revisions (&revs,NULL );/* write prerequisites */ -if (compute_and_write_prerequisites (bundle_fd, &revs, argc, argv)) +if (compute_and_write_prerequisites (bundle_fd, &revs, argc, argv)) { +if (!bundle_to_stdout) +close (bundle_fd);return -1 ; + } argc =setup_revisions (argc, argv, &revs,NULL );
@@ -447,8 +450,11 @@ int create_bundle(struct bundle_header *header, const char *path, ref_count =write_bundle_refs (bundle_fd, &revs);if (!ref_count)die (_ ("Refusing to create empty bundle." )); -else if (ref_count <0 ) +else if (ref_count <0 ) { +if (!bundle_to_stdout) +close (bundle_fd);return -1 ; + }/* write pack */ if (write_pack_data (bundle_fd, &revs))
Signature · 1 line
2.8.0.8.g27a27a6.dirty
Re: [PATCH 5/6] bundle: don't leak an fd in case of early return
Quoted 14 lines · Stefan Beller
In successful operation
write_pack_datawill close thebundle_fd, but when we exit early, we need to take care of the file descriptor ourselves.Signed-off-by Stefan Beller <[email protected]>--- bundle.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)bundle.c +0
-0
bundle.c int create_bundle(struct bundle_header *header, const char *path, · line 441
Quoted 9 lines
bundle.c +4
-1@@ -434,8 +434,11 @@ int create_bundle(struct bundle_header *header, const char *path,init_revisions (&revs,NULL );/* write prerequisites */ -if (compute_and_write_prerequisites (bundle_fd, &revs, argc, argv)) +if (compute_and_write_prerequisites (bundle_fd, &revs, argc, argv)) { +if (!bundle_to_stdout) +close (bundle_fd);return -1 ; + }
Makes sense. Should we also be rolling back the lock file? It happens automatically at program exit, of course, but we are in library code here that should not rely on that.
bundle.c int create_bundle(struct bundle_header *header, const char *path, · line 457
Quoted 10 lines
bundle.c +4
-1@@ -447,8 +450,11 @@ int create_bundle(struct bundle_header *header, const char *path, ref_count =write_bundle_refs (bundle_fd, &revs);if (!ref_count)die (_ ("Refusing to create empty bundle." )); -else if (ref_count <0 ) +else if (ref_count <0 ) { +if (!bundle_to_stdout) +close (bundle_fd);return -1 ; + }
Ditto here, and in the error return from write_pack_data(). There are enough spots that it may be worth setting up a "goto err" path.
-Peff
PATCH 6/6 credential-cache, send_request: close fd when done
In reply to Stefan BellerNo need to keep it open any further.
--- credential-cache.c | 1 + 1 file changed, 1 insertion(+)
credential-cache.c +1 -0
@@ -32,6 +32,7 @@ static int send_request(const char *socket, const struct strbuf *out)write_or_die (1 , in, r); got_data =1 ; } +close (fd);return got_data; }
Signature · 1 line
2.8.0.8.g27a27a6.dirty
Re: [PATCH 6/6] credential-cache, send_request: close fd when done
Quoted 12 lines · Stefan Beller
No need to keep it open any further.
Signed-off-by Stefan Beller <[email protected]>--- credential-cache.c | 1 + 1 file changed, 1 insertion(+)credential-cache.c +0
-0
credential-cache.c static int send_request(const char *socket, const struct strbuf *out) · line 37
Quoted 6 lines
credential-cache.c +1
-0@@ -32,6 +32,7 @@ static int send_request(const char *socket, const struct strbuf *out)write_or_die (1 , in, r); got_data =1 ; } +close (fd);return got_data; }
Looks good. I think nobody ever noticed because credential-cache basically sends off the request and then exits.
-Peff
Re: [PATCH 1/6] path.c: allocate enough memory for string
In reply to Eric SunshineQuoted 5 lines · Eric Sunshine
Quoted 4 lines · Stefan Beller
strlenreturns the length of a string without the terminating null byte. To make sure enough memory is allocated we need to passstrlen(..) + 1to the allocation function.
Quoted 14 lines
path.c static struct trie *make_trie_node(const char *key, void *value) · line 159
Quoted 10 lines
Signed-off-by Stefan Beller <[email protected]>---
path.c +1
-1@@ -155,7 +155,7 @@ static struct trie *make_trie_node(const char *key, void *value)struct trie *new_node =xcalloc (1 ,sizeof (*new_node)); new_node->len =strlen (key);if (new_node->len) { - new_node->contents =xmalloc (new_node->len); + new_node->contents =xmalloc (new_node->len +1 );memcpy (new_node->contents, key, new_node->len);Huh? This is a trie. It never accesses 'contents' as a NUL-terminated string. Plus, no NUL is ever even copied, thus this is just overallocating. How is this an improvement?
By using strlen, I assumed it was a standard C string. I missed that, though.
Quoted 4 lines
Quoted 4 lines
path.c +0
-1} new_node->value = value; --
Re: [PATCH 1/6] path.c: allocate enough memory for string
Quoted 21 lines · Stefan Beller
Quoted 5 lines · Eric Sunshine
Quoted 4 lines · Stefan Beller
strlenreturns the length of a string without the terminating null byte. To make sure enough memory is allocated we need to passstrlen(..) + 1to the allocation function.Quoted 14 lines
path.c static struct trie *make_trie_node(const char *key, void *value) · line 159
Quoted 10 lines
Signed-off-by Stefan Beller <[email protected]>---
path.c +1
-1@@ -155,7 +155,7 @@ static struct trie *make_trie_node(const char *key, void *value)struct trie *new_node =xcalloc (1 ,sizeof (*new_node)); new_node->len =strlen (key);if (new_node->len) { - new_node->contents =xmalloc (new_node->len); + new_node->contents =xmalloc (new_node->len +1 );memcpy (new_node->contents, key, new_node->len);Huh? This is a trie. It never accesses 'contents' as a NUL-terminated string. Plus, no NUL is ever even copied, thus this is just overallocating. How is this an improvement?
Quoted 2 lines
By using strlen, I assumed it was a standard C string. I missed that, though.
You took hint from a wrong place. You are auditing the destination buffer, so the correct place to take hint from is the memcpy() that touches the destination.
Re: [PATCH 3/6] notes: don't leak memory in git_config_get_notes_strategy
In reply to Jeff KingQuoted 3 lines · Jeff King
I don't think this is wrong, but would it perhaps be simpler to call
git_config_get_value()in the first place, which does not make a copy of the string?
Yup, I agree.
Re: [PATCH 4/6] abbrev_sha1_in_line: don't leak memory
In reply to Jeff KingQuoted 11 lines · Jeff King
Quoted 9 lines · Eric Sunshine
The implementation of
strbuf_list_free()is this:struct strbuf **s = sbs; while (*s) { strbuf_release(*s); free(*s++); } free(sbs);
Quoted 4 lines
Quoted 2 lines
which means that
wt-status.cis leaking not only 'split', but also each element of split[], right?Yeah, I didn't notice that, but I think you're right.
Correct.
I suspect that we would be better off in the longer term if we made conscious effort to deprecate and eradicate the use of strbuf_split* API functions. They are easy to write crappy code with, inefficient, and error prone. You would rarely need to have N resulting pieces as strbufs to be easily manipulatable [*1*].
The function can be written by not using the "split and then rebuild" pattern, perhaps like so, and the result is even easier to read and understand, I would say. A sample rewrite is attached at the end.
[Footnote]
*1* I wouldn't be this harsh if the function were to fill an
array of pointers or offsets into the original string.
wt-status.c | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-)
wt-status.c +19 -24
@@ -1037,35 +1037,30 @@ static int split_commit_in_progress(struct wt_status *s)*/ static void abbrev_sha1_in_line (struct strbuf *line) { -struct strbuf **split; -int i; +const char *cp, *ep, *abbrev; +unsigned char sha1[20 ]; -if (starts_with (line->buf,"exec " ) || -starts_with (line->buf,"x " )) +/* the oddball "exec" does not have 40-hex as the second token */ +if (starts_with (line->buf,"exec " ) ||starts_with (line->buf,"x " ))return ; - split =strbuf_split_max (line,' ' ,3 ); -if (split[0 ] && split[1 ]) { -unsigned char sha1[20 ]; -const char *abbrev; +/* find the second token on the line */ + cp =strchr (line->buf,' ' ); +if (!cp) +return ; + cp++; + ep =strchr (cp,' ' ); +if (!ep) +return ; -/* -* strbuf_split_max left a space. Trim it and re-add -* it after abbreviation. -*/ -strbuf_trim (split[1 ]); -if (!get_sha1 (split[1 ]->buf, sha1)) { - abbrev =find_unique_abbrev (sha1,DEFAULT_ABBREV ); -strbuf_reset (split[1 ]); -strbuf_addf (split[1 ],"%s " , abbrev); -strbuf_reset (line); -for (i =0 ; split[i]; i++) -strbuf_addf (line,"%s" , split[i]->buf); - } - } -for (i =0 ; split[i]; i++) -strbuf_release (split[i]); +/* is it 40-hex? */ +if (ep - cp !=GIT_SHA1_HEXSZ ||get_sha1_hex (cp, sha1)) +return ; +/* replace it with its abbreviation */ + abbrev =find_unique_abbrev (sha1,DEFAULT_ABBREV ); +strbuf_splice (line, cp - line->buf,GIT_SHA1_HEXSZ , + abbrev,strlen (abbrev)); }static void read_rebase_todolist (const char *fname,struct string_list *lines)
Re: [PATCH 4/6] abbrev_sha1_in_line: don't leak memory
Quoted 18 lines · Junio C Hamano
Quoted 11 lines · Jeff King
Quoted 9 lines · Eric Sunshine
The implementation of
strbuf_list_free()is this:struct strbuf **s = sbs; while (*s) { strbuf_release(*s); free(*s++); } free(sbs);Quoted 4 lines
Quoted 2 lines
which means that
wt-status.cis leaking not only 'split', but also each element of split[], right?Yeah, I didn't notice that, but I think you're right.
Quoted 8 lines
Correct.
I suspect that we would be better off in the longer term if we made conscious effort to deprecate and eradicate the use of strbuf_split* API functions. They are easy to write crappy code with, inefficient, and error prone. You would rarely need to have N resulting pieces as strbufs to be easily manipulatable [*1*].
Yeah, I agree that it is a clunky interface, and I would be happy to see it go away. Many callers would be better off with string_list_split(). When I've looked in the past, though, converting some of the callers was somewhat non-trivial.
But in this case...
Quoted 4 lines
The function can be written by not using the "split and then rebuild" pattern, perhaps like so, and the result is even easier to read and understand, I would say. A sample rewrite is attached at the end.
I agree that the function is much simpler without it.
wt-status.c static int split_commit_in_progress(struct wt_status *s) · line 1054
Quoted 8 lines
wt-status.c +8
-0+/* find the second token on the line */ + cp =strchr (line->buf,' ' ); +if (!cp) +return ; + cp++; + ep =strchr (cp,' ' ); +if (!ep) +return ;
Would we ever see "cmd sha1" without a third token? If so, we'd want:
ep = strchrnul(cp, ' ');
-Peff
Re: [PATCH 5/6] bundle: don't leak an fd in case of early return
In reply to Jeff KingQuoted 9 lines · Jeff King
bundle.c int create_bundle(struct bundle_header *header, const char *path, · line 441
Quoted 5 lines
bundle.c +4
-0+if (compute_and_write_prerequisites (bundle_fd, &revs, argc, argv)) { +if (!bundle_to_stdout) +close (bundle_fd);return -1 ; + }Makes sense. Should we also be rolling back the lock file? It happens automatically at program exit, of course, but we are in library code here that should not rely on that.
Yeah, I agree. I suspect that the original wasn't even meant to be used in a "library-ish" fashion, but as long as we are adding this close(), we should also be doing the rollback.
Thanks.