rugged 0.24.0b13 → 0.24.0b14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/ext/rugged/rugged_commit.c +6 -6
  2. data/ext/rugged/rugged_revwalk.c +7 -3
  3. data/ext/rugged/rugged_settings.c +5 -0
  4. data/lib/rugged/tag.rb +1 -1
  5. data/lib/rugged/version.rb +1 -1
  6. data/vendor/libgit2/CMakeLists.txt +21 -8
  7. data/vendor/libgit2/include/git2/commit.h +6 -0
  8. data/vendor/libgit2/include/git2/common.h +15 -0
  9. data/vendor/libgit2/include/git2/errors.h +0 -5
  10. data/vendor/libgit2/include/git2/rebase.h +1 -1
  11. data/vendor/libgit2/include/git2/sys/filter.h +34 -25
  12. data/vendor/libgit2/include/git2/sys/index.h +1 -1
  13. data/vendor/libgit2/src/checkout.c +1 -1
  14. data/vendor/libgit2/src/commit.c +44 -12
  15. data/vendor/libgit2/src/common.h +11 -0
  16. data/vendor/libgit2/src/crlf.c +1 -1
  17. data/vendor/libgit2/src/diff_print.c +5 -1
  18. data/vendor/libgit2/src/diff_tform.c +16 -11
  19. data/vendor/libgit2/src/fileops.c +8 -15
  20. data/vendor/libgit2/src/filter.c +155 -124
  21. data/vendor/libgit2/src/filter.h +2 -0
  22. data/vendor/libgit2/src/global.c +56 -162
  23. data/vendor/libgit2/src/index.c +68 -30
  24. data/vendor/libgit2/src/index.h +1 -1
  25. data/vendor/libgit2/src/iterator.c +9 -3
  26. data/vendor/libgit2/src/netops.c +4 -0
  27. data/vendor/libgit2/src/object.c +26 -0
  28. data/vendor/libgit2/src/object.h +23 -0
  29. data/vendor/libgit2/src/openssl_stream.c +135 -3
  30. data/vendor/libgit2/src/openssl_stream.h +2 -0
  31. data/vendor/libgit2/src/pack-objects.c +6 -6
  32. data/vendor/libgit2/src/pack.c +18 -1
  33. data/vendor/libgit2/src/path.c +7 -3
  34. data/vendor/libgit2/src/path.h +14 -4
  35. data/vendor/libgit2/src/pool.c +78 -30
  36. data/vendor/libgit2/src/pool.h +28 -0
  37. data/vendor/libgit2/src/posix.c +5 -2
  38. data/vendor/libgit2/src/rebase.c +12 -10
  39. data/vendor/libgit2/src/refdb_fs.c +3 -4
  40. data/vendor/libgit2/src/refs.c +1 -7
  41. data/vendor/libgit2/src/refspec.c +4 -4
  42. data/vendor/libgit2/src/remote.c +2 -2
  43. data/vendor/libgit2/src/revwalk.c +1 -2
  44. data/vendor/libgit2/src/settings.c +9 -0
  45. data/vendor/libgit2/src/signature.c +2 -3
  46. data/vendor/libgit2/src/submodule.c +2 -2
  47. data/vendor/libgit2/src/thread-utils.h +1 -1
  48. data/vendor/libgit2/src/transports/smart_pkt.c +15 -9
  49. data/vendor/libgit2/src/transports/smart_protocol.c +2 -0
  50. data/vendor/libgit2/src/transports/winhttp.c +1 -1
  51. data/vendor/libgit2/src/tree.c +31 -10
  52. data/vendor/libgit2/src/unix/map.c +1 -1
  53. data/vendor/libgit2/src/unix/posix.h +15 -1
  54. data/vendor/libgit2/src/win32/posix.h +6 -4
  55. data/vendor/libgit2/src/win32/posix_w32.c +18 -2
  56. data/vendor/libgit2/src/win32/utf-conv.c +3 -18
  57. data/vendor/libgit2/src/win32/w32_util.h +44 -11
  58. data/vendor/libgit2/src/win32/win32-compat.h +10 -0
  59. data/vendor/libgit2/src/xdiff/xmerge.c +2 -0
  60. metadata +416 -405
  61. checksums.yaml +0 -7
@@ -564,15 +564,16 @@ extern int git_path_from_url_or_path(git_buf *local_path_out, const char *url_or
564
564
  #define GIT_PATH_REJECT_TRAILING_COLON (1 << 6)
565
565
  #define GIT_PATH_REJECT_DOS_PATHS (1 << 7)
566
566
  #define GIT_PATH_REJECT_NT_CHARS (1 << 8)
567
- #define GIT_PATH_REJECT_DOT_GIT_HFS (1 << 9)
568
- #define GIT_PATH_REJECT_DOT_GIT_NTFS (1 << 10)
567
+ #define GIT_PATH_REJECT_DOT_GIT_LITERAL (1 << 9)
568
+ #define GIT_PATH_REJECT_DOT_GIT_HFS (1 << 10)
569
+ #define GIT_PATH_REJECT_DOT_GIT_NTFS (1 << 11)
569
570
 
570
571
  /* Default path safety for writing files to disk: since we use the
571
572
  * Win32 "File Namespace" APIs ("\\?\") we need to protect from
572
573
  * paths that the normal Win32 APIs would not write.
573
574
  */
574
575
  #ifdef GIT_WIN32
575
- # define GIT_PATH_REJECT_DEFAULTS \
576
+ # define GIT_PATH_REJECT_FILESYSTEM_DEFAULTS \
576
577
  GIT_PATH_REJECT_TRAVERSAL | \
577
578
  GIT_PATH_REJECT_BACKSLASH | \
578
579
  GIT_PATH_REJECT_TRAILING_DOT | \
@@ -581,9 +582,18 @@ extern int git_path_from_url_or_path(git_buf *local_path_out, const char *url_or
581
582
  GIT_PATH_REJECT_DOS_PATHS | \
582
583
  GIT_PATH_REJECT_NT_CHARS
583
584
  #else
584
- # define GIT_PATH_REJECT_DEFAULTS GIT_PATH_REJECT_TRAVERSAL
585
+ # define GIT_PATH_REJECT_FILESYSTEM_DEFAULTS \
586
+ GIT_PATH_REJECT_TRAVERSAL
585
587
  #endif
586
588
 
589
+ /* Paths that should never be written into the working directory. */
590
+ #define GIT_PATH_REJECT_WORKDIR_DEFAULTS \
591
+ GIT_PATH_REJECT_FILESYSTEM_DEFAULTS | GIT_PATH_REJECT_DOT_GIT
592
+
593
+ /* Paths that should never be written to the index. */
594
+ #define GIT_PATH_REJECT_INDEX_DEFAULTS \
595
+ GIT_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT
596
+
587
597
  /*
588
598
  * Determine whether a path is a valid git path or not - this must not contain
589
599
  * a '.' or '..' component, or a component that is ".git" (in any case).
@@ -28,6 +28,7 @@ uint32_t git_pool__system_page_size(void)
28
28
  return size;
29
29
  }
30
30
 
31
+ #ifndef GIT_DEBUG_POOL
31
32
  void git_pool_init(git_pool *pool, uint32_t item_size)
32
33
  {
33
34
  assert(pool);
@@ -50,18 +51,6 @@ void git_pool_clear(git_pool *pool)
50
51
  pool->pages = NULL;
51
52
  }
52
53
 
53
- void git_pool_swap(git_pool *a, git_pool *b)
54
- {
55
- git_pool temp;
56
-
57
- if (a == b)
58
- return;
59
-
60
- memcpy(&temp, a, sizeof(temp));
61
- memcpy(a, b, sizeof(temp));
62
- memcpy(b, &temp, sizeof(temp));
63
- }
64
-
65
54
  static void *pool_alloc_page(git_pool *pool, uint32_t size)
66
55
  {
67
56
  git_pool_page *page;
@@ -95,6 +84,83 @@ static void *pool_alloc(git_pool *pool, uint32_t size)
95
84
  return ptr;
96
85
  }
97
86
 
87
+ uint32_t git_pool__open_pages(git_pool *pool)
88
+ {
89
+ uint32_t ct = 0;
90
+ git_pool_page *scan;
91
+ for (scan = pool->pages; scan != NULL; scan = scan->next) ct++;
92
+ return ct;
93
+ }
94
+
95
+ bool git_pool__ptr_in_pool(git_pool *pool, void *ptr)
96
+ {
97
+ git_pool_page *scan;
98
+ for (scan = pool->pages; scan != NULL; scan = scan->next)
99
+ if ((void *)scan->data <= ptr &&
100
+ (void *)(((char *)scan->data) + scan->size) > ptr)
101
+ return true;
102
+ return false;
103
+ }
104
+
105
+ #else
106
+
107
+ static int git_pool__ptr_cmp(const void * a, const void * b)
108
+ {
109
+ if(a > b) {
110
+ return 1;
111
+ }
112
+ if(a < b) {
113
+ return -1;
114
+ }
115
+ else {
116
+ return 0;
117
+ }
118
+ }
119
+
120
+ void git_pool_init(git_pool *pool, uint32_t item_size)
121
+ {
122
+ assert(pool);
123
+ assert(item_size >= 1);
124
+
125
+ memset(pool, 0, sizeof(git_pool));
126
+ pool->item_size = item_size;
127
+ pool->page_size = git_pool__system_page_size();
128
+ git_vector_init(&pool->allocations, 100, git_pool__ptr_cmp);
129
+ }
130
+
131
+ void git_pool_clear(git_pool *pool)
132
+ {
133
+ git_vector_free_deep(&pool->allocations);
134
+ }
135
+
136
+ static void *pool_alloc(git_pool *pool, uint32_t size) {
137
+ void *ptr = NULL;
138
+ if((ptr = git__malloc(size)) == NULL) {
139
+ return NULL;
140
+ }
141
+ git_vector_insert_sorted(&pool->allocations, ptr, NULL);
142
+ return ptr;
143
+ }
144
+
145
+ bool git_pool__ptr_in_pool(git_pool *pool, void *ptr)
146
+ {
147
+ size_t pos;
148
+ return git_vector_bsearch(&pos, &pool->allocations, ptr) != GIT_ENOTFOUND;
149
+ }
150
+ #endif
151
+
152
+ void git_pool_swap(git_pool *a, git_pool *b)
153
+ {
154
+ git_pool temp;
155
+
156
+ if (a == b)
157
+ return;
158
+
159
+ memcpy(&temp, a, sizeof(temp));
160
+ memcpy(a, b, sizeof(temp));
161
+ memcpy(b, &temp, sizeof(temp));
162
+ }
163
+
98
164
  static uint32_t alloc_size(git_pool *pool, uint32_t count)
99
165
  {
100
166
  const uint32_t align = sizeof(void *) - 1;
@@ -168,21 +234,3 @@ char *git_pool_strcat(git_pool *pool, const char *a, const char *b)
168
234
  }
169
235
  return ptr;
170
236
  }
171
-
172
- uint32_t git_pool__open_pages(git_pool *pool)
173
- {
174
- uint32_t ct = 0;
175
- git_pool_page *scan;
176
- for (scan = pool->pages; scan != NULL; scan = scan->next) ct++;
177
- return ct;
178
- }
179
-
180
- bool git_pool__ptr_in_pool(git_pool *pool, void *ptr)
181
- {
182
- git_pool_page *scan;
183
- for (scan = pool->pages; scan != NULL; scan = scan->next)
184
- if ((void *)scan->data <= ptr &&
185
- (void *)(((char *)scan->data) + scan->size) > ptr)
186
- return true;
187
- return false;
188
- }
@@ -8,9 +8,11 @@
8
8
  #define INCLUDE_pool_h__
9
9
 
10
10
  #include "common.h"
11
+ #include "vector.h"
11
12
 
12
13
  typedef struct git_pool_page git_pool_page;
13
14
 
15
+ #ifndef GIT_DEBUG_POOL
14
16
  /**
15
17
  * Chunked allocator.
16
18
  *
@@ -33,6 +35,30 @@ typedef struct {
33
35
  uint32_t page_size; /* size of page in bytes */
34
36
  } git_pool;
35
37
 
38
+ #else
39
+
40
+ /**
41
+ * Debug chunked allocator.
42
+ *
43
+ * Acts just like `git_pool` but instead of actually pooling allocations it
44
+ * passes them through to `git__malloc`. This makes it possible to easily debug
45
+ * systems that use `git_pool` using valgrind.
46
+ *
47
+ * In order to track allocations during the lifetime of the pool we use a
48
+ * `git_vector`. When the pool is deallocated everything in the vector is
49
+ * freed.
50
+ *
51
+ * `API is exactly the same as the standard `git_pool` with one exception.
52
+ * Since we aren't allocating pages to hand out in chunks we can't easily
53
+ * implement `git_pool__open_pages`.
54
+ */
55
+ typedef struct {
56
+ git_vector allocations;
57
+ uint32_t item_size;
58
+ uint32_t page_size;
59
+ } git_pool;
60
+ #endif
61
+
36
62
  /**
37
63
  * Initialize a pool.
38
64
  *
@@ -98,7 +124,9 @@ extern char *git_pool_strcat(git_pool *pool, const char *a, const char *b);
98
124
  /*
99
125
  * Misc utilities
100
126
  */
127
+ #ifndef GIT_DEBUG_POOL
101
128
  extern uint32_t git_pool__open_pages(git_pool *pool);
129
+ #endif
102
130
  extern bool git_pool__ptr_in_pool(git_pool *pool, void *ptr);
103
131
 
104
132
  #endif
@@ -62,8 +62,11 @@ int p_getaddrinfo(
62
62
  ai = ainfo;
63
63
 
64
64
  for (p = 1; ainfo->ai_hostent->h_addr_list[p] != NULL; p++) {
65
- ai->ai_next = malloc(sizeof(struct addrinfo));
66
- memcpy(&ai->ai_next, ainfo, sizeof(struct addrinfo));
65
+ if (!(ai->ai_next = malloc(sizeof(struct addrinfo)))) {
66
+ p_freeaddrinfo(ainfo);
67
+ return -1;
68
+ }
69
+ memcpy(ai->ai_next, ainfo, sizeof(struct addrinfo));
67
70
  memcpy(&ai->ai_next->ai_addr_in.sin_addr,
68
71
  ainfo->ai_hostent->h_addr_list[p],
69
72
  ainfo->ai_hostent->h_length);
@@ -257,12 +257,12 @@ done:
257
257
  return error;
258
258
  }
259
259
 
260
- static git_rebase *rebase_alloc(const git_rebase_options *rebase_opts)
260
+ static int rebase_alloc(git_rebase **out, const git_rebase_options *rebase_opts)
261
261
  {
262
262
  git_rebase *rebase = git__calloc(1, sizeof(git_rebase));
263
+ GITERR_CHECK_ALLOC(rebase);
263
264
 
264
- if (!rebase)
265
- return NULL;
265
+ *out = NULL;
266
266
 
267
267
  if (rebase_opts)
268
268
  memcpy(&rebase->options, rebase_opts, sizeof(git_rebase_options));
@@ -270,14 +270,16 @@ static git_rebase *rebase_alloc(const git_rebase_options *rebase_opts)
270
270
  git_rebase_init_options(&rebase->options, GIT_REBASE_OPTIONS_VERSION);
271
271
 
272
272
  if (rebase_opts && rebase_opts->rewrite_notes_ref) {
273
- if ((rebase->options.rewrite_notes_ref = git__strdup(rebase_opts->rewrite_notes_ref)) == NULL)
274
- return NULL;
273
+ rebase->options.rewrite_notes_ref = git__strdup(rebase_opts->rewrite_notes_ref);
274
+ GITERR_CHECK_ALLOC(rebase->options.rewrite_notes_ref);
275
275
  }
276
276
 
277
277
  if ((rebase->options.checkout_options.checkout_strategy & (GIT_CHECKOUT_SAFE | GIT_CHECKOUT_FORCE)) == 0)
278
278
  rebase->options.checkout_options.checkout_strategy = GIT_CHECKOUT_SAFE;
279
279
 
280
- return rebase;
280
+ *out = rebase;
281
+
282
+ return 0;
281
283
  }
282
284
 
283
285
  static int rebase_check_versions(const git_rebase_options *given_opts)
@@ -305,8 +307,8 @@ int git_rebase_open(
305
307
  if ((error = rebase_check_versions(given_opts)) < 0)
306
308
  return error;
307
309
 
308
- rebase = rebase_alloc(given_opts);
309
- GITERR_CHECK_ALLOC(rebase);
310
+ if (rebase_alloc(&rebase, given_opts) < 0)
311
+ return -1;
310
312
 
311
313
  rebase->repo = repo;
312
314
 
@@ -708,8 +710,8 @@ int git_rebase_init(
708
710
  branch = head_branch;
709
711
  }
710
712
 
711
- rebase = rebase_alloc(given_opts);
712
- GITERR_CHECK_ALLOC(rebase);
713
+ if (rebase_alloc(&rebase, given_opts) < 0)
714
+ return -1;
713
715
 
714
716
  rebase->repo = repo;
715
717
  rebase->inmemory = inmemory;
@@ -717,7 +717,7 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
717
717
 
718
718
  assert(file && backend && name);
719
719
 
720
- if (!git_path_isvalid(backend->repo, name, GIT_PATH_REJECT_DEFAULTS)) {
720
+ if (!git_path_isvalid(backend->repo, name, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
721
721
  giterr_set(GITERR_INVALID, "Invalid reference name '%s'.", name);
722
722
  return GIT_EINVALIDSPEC;
723
723
  }
@@ -1512,8 +1512,7 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
1512
1512
  #undef seek_forward
1513
1513
 
1514
1514
  fail:
1515
- if (entry)
1516
- git_reflog_entry__free(entry);
1515
+ git_reflog_entry__free(entry);
1517
1516
 
1518
1517
  return -1;
1519
1518
  }
@@ -1672,7 +1671,7 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char
1672
1671
 
1673
1672
  repo = backend->repo;
1674
1673
 
1675
- if (!git_path_isvalid(backend->repo, refname, GIT_PATH_REJECT_DEFAULTS)) {
1674
+ if (!git_path_isvalid(backend->repo, refname, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
1676
1675
  giterr_set(GITERR_INVALID, "Invalid reference name '%s'.", refname);
1677
1676
  return GIT_EINVALIDSPEC;
1678
1677
  }
@@ -377,15 +377,9 @@ static int reference__create(
377
377
  return error;
378
378
 
379
379
  if (oid != NULL) {
380
- git_odb *odb;
381
-
382
380
  assert(symbolic == NULL);
383
381
 
384
- /* Sanity check the reference being created - target must exist. */
385
- if ((error = git_repository_odb__weakptr(&odb, repo)) < 0)
386
- return error;
387
-
388
- if (!git_odb_exists(odb, oid)) {
382
+ if (!git_object__is_valid(repo, oid, GIT_OBJ_ANY)) {
389
383
  giterr_set(GITERR_REFERENCE,
390
384
  "Target OID for the reference doesn't exist on the repository");
391
385
  return -1;
@@ -323,8 +323,8 @@ int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs)
323
323
  if (git__prefixcmp(spec->src, GIT_REFS_DIR)) {
324
324
  for (j = 0; formatters[j]; j++) {
325
325
  git_buf_clear(&buf);
326
- if (git_buf_printf(&buf, formatters[j], spec->src) < 0)
327
- return -1;
326
+ git_buf_printf(&buf, formatters[j], spec->src);
327
+ GITERR_CHECK_ALLOC_BUF(&buf);
328
328
 
329
329
  key.name = (char *) git_buf_cstr(&buf);
330
330
  if (!git_vector_search(&pos, refs, &key)) {
@@ -348,8 +348,8 @@ int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs)
348
348
  git_buf_puts(&buf, GIT_REFS_HEADS_DIR);
349
349
  }
350
350
 
351
- if (git_buf_puts(&buf, spec->dst) < 0)
352
- return -1;
351
+ git_buf_puts(&buf, spec->dst);
352
+ GITERR_CHECK_ALLOC_BUF(&buf);
353
353
 
354
354
  cur->dst = git_buf_detach(&buf);
355
355
  }
@@ -208,8 +208,8 @@ static int create_internal(git_remote **out, git_repository *repo, const char *n
208
208
 
209
209
  remote->repo = repo;
210
210
 
211
- if (git_vector_init(&remote->refs, 32, NULL) < 0 ||
212
- canonicalize_url(&canonical_url, url) < 0)
211
+ if ((error = git_vector_init(&remote->refs, 32, NULL)) < 0 ||
212
+ (error = canonicalize_url(&canonical_url, url)) < 0)
213
213
  goto on_error;
214
214
 
215
215
  remote->url = apply_insteadof(repo->_config, canonical_url.ptr, GIT_DIRECTION_FETCH);
@@ -223,8 +223,7 @@ static int push_glob(git_revwalk *walk, const char *glob, int hide)
223
223
  git_buf_joinpath(&buf, GIT_REFS_DIR, glob);
224
224
  else
225
225
  git_buf_puts(&buf, glob);
226
- if (git_buf_oom(&buf))
227
- return -1;
226
+ GITERR_CHECK_ALLOC_BUF(&buf);
228
227
 
229
228
  /* If no '?', '*' or '[' exist, we append '/ *' to the glob */
230
229
  wildcard = strcspn(glob, "?*[");
@@ -14,6 +14,7 @@
14
14
  #include "sysdir.h"
15
15
  #include "cache.h"
16
16
  #include "global.h"
17
+ #include "object.h"
17
18
 
18
19
  void git_libgit2_version(int *major, int *minor, int *rev)
19
20
  {
@@ -181,6 +182,14 @@ int git_libgit2_opts(int key, ...)
181
182
  }
182
183
 
183
184
  break;
185
+
186
+ case GIT_OPT_ENABLE_STRICT_OBJECT_CREATION:
187
+ git_object__strict_input_validation = (va_arg(ap, int) != 0);
188
+ break;
189
+
190
+ default:
191
+ giterr_set(GITERR_INVALID, "invalid option key");
192
+ error = -1;
184
193
  }
185
194
 
186
195
  va_end(ap);
@@ -79,10 +79,9 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema
79
79
  GITERR_CHECK_ALLOC(p);
80
80
 
81
81
  p->name = extract_trimmed(name, strlen(name));
82
+ GITERR_CHECK_ALLOC(p->name);
82
83
  p->email = extract_trimmed(email, strlen(email));
83
-
84
- if (p->name == NULL || p->email == NULL)
85
- return -1; /* oom */
84
+ GITERR_CHECK_ALLOC(p->email);
86
85
 
87
86
  if (p->name[0] == '\0' || p->email[0] == '\0') {
88
87
  git_signature_free(p);
@@ -778,9 +778,9 @@ int git_submodule_add_to_index(git_submodule *sm, int write_index)
778
778
  if ((error = git_commit_lookup(&head, sm_repo, &sm->wd_oid)) < 0)
779
779
  goto cleanup;
780
780
 
781
- entry.ctime.seconds = git_commit_time(head);
781
+ entry.ctime.seconds = (int32_t)git_commit_time(head);
782
782
  entry.ctime.nanoseconds = 0;
783
- entry.mtime.seconds = git_commit_time(head);
783
+ entry.mtime.seconds = (int32_t)git_commit_time(head);
784
784
  entry.mtime.nanoseconds = 0;
785
785
 
786
786
  git_commit_free(head);
@@ -275,7 +275,7 @@ GIT_INLINE(int) git_atomic_get(git_atomic *a)
275
275
 
276
276
  extern int git_online_cpus(void);
277
277
 
278
- #if defined(GIT_THREADS) && defined(GIT_WIN32)
278
+ #if defined(GIT_THREADS) && defined(_MSC_VER)
279
279
  # define GIT_MEMORY_BARRIER MemoryBarrier()
280
280
  #elif defined(GIT_THREADS)
281
281
  # define GIT_MEMORY_BARRIER __sync_synchronize()
@@ -271,6 +271,7 @@ static int ok_pkt(git_pkt **out, const char *line, size_t len)
271
271
  line += 3; /* skip "ok " */
272
272
  if (!(ptr = strchr(line, '\n'))) {
273
273
  giterr_set(GITERR_NET, "Invalid packet line");
274
+ git__free(pkt);
274
275
  return -1;
275
276
  }
276
277
  len = ptr - line;
@@ -295,13 +296,12 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len)
295
296
  pkt = git__malloc(sizeof(*pkt));
296
297
  GITERR_CHECK_ALLOC(pkt);
297
298
 
299
+ pkt->ref = NULL;
298
300
  pkt->type = GIT_PKT_NG;
299
301
 
300
302
  line += 3; /* skip "ng " */
301
- if (!(ptr = strchr(line, ' '))) {
302
- giterr_set(GITERR_NET, "Invalid packet line");
303
- return -1;
304
- }
303
+ if (!(ptr = strchr(line, ' ')))
304
+ goto out_err;
305
305
  len = ptr - line;
306
306
 
307
307
  GITERR_CHECK_ALLOC_ADD(&alloclen, len, 1);
@@ -312,10 +312,8 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len)
312
312
  pkt->ref[len] = '\0';
313
313
 
314
314
  line = ptr + 1;
315
- if (!(ptr = strchr(line, '\n'))) {
316
- giterr_set(GITERR_NET, "Invalid packet line");
317
- return -1;
318
- }
315
+ if (!(ptr = strchr(line, '\n')))
316
+ goto out_err;
319
317
  len = ptr - line;
320
318
 
321
319
  GITERR_CHECK_ALLOC_ADD(&alloclen, len, 1);
@@ -327,6 +325,12 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len)
327
325
 
328
326
  *out = (git_pkt *)pkt;
329
327
  return 0;
328
+
329
+ out_err:
330
+ giterr_set(GITERR_NET, "Invalid packet line");
331
+ git__free(pkt->ref);
332
+ git__free(pkt);
333
+ return -1;
330
334
  }
331
335
 
332
336
  static int unpack_pkt(git_pkt **out, const char *line, size_t len)
@@ -540,7 +544,9 @@ static int buffer_want_with_caps(const git_remote_head *head, transport_smart_ca
540
544
  "%04xwant %s %s\n", (unsigned int)len, oid, git_buf_cstr(&str));
541
545
  git_buf_free(&str);
542
546
 
543
- return git_buf_oom(buf);
547
+ GITERR_CHECK_ALLOC_BUF(buf);
548
+
549
+ return 0;
544
550
  }
545
551
 
546
552
  /*