Merge pull request #2612 from ethomson/warnings Clean up some warnings
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
diff --git a/src/describe.c b/src/describe.c
index 9b41316..fb39c58 100644
--- a/src/describe.c
+++ b/src/describe.c
@@ -397,7 +397,7 @@ static int show_suffix(
const git_oid* id,
size_t abbrev_size)
{
- int error, size;
+ int error, size = 0;
char hex_oid[GIT_OID_HEXSZ];
@@ -818,7 +818,8 @@ int git_describe_format(git_buf *out, const git_describe_result *result, const g
/* If we didn't find *any* tags, we fall back to the commit's id */
if (result->fallback_to_id) {
char hex_oid[GIT_OID_HEXSZ + 1] = {0};
- int size;
+ int size = 0;
+
if ((error = find_unique_abbrev_size(
&size, repo, &result->commit_id, opts.abbreviated_size)) < 0)
return -1;
diff --git a/src/global.c b/src/global.c
index 514b96c..1e6bf82 100644
--- a/src/global.c
+++ b/src/global.c
@@ -63,8 +63,12 @@ void openssl_locking_function(int mode, int n, const char *file, int line)
git_mutex_unlock(&openssl_locks[n]);
}
}
-#endif
+static void shutdown_ssl(void)
+{
+ git__free(openssl_locks);
+}
+#endif
static void init_ssl(void)
{
@@ -112,6 +116,8 @@ static void init_ssl(void)
CRYPTO_set_locking_callback(openssl_locking_function);
}
+
+ git__on_shutdown(shutdown_ssl);
# endif
#endif
}
diff --git a/src/mwindow.c b/src/mwindow.c
index 1d64d26..0444cd9 100644
--- a/src/mwindow.c
+++ b/src/mwindow.c
@@ -41,6 +41,8 @@ int git_mwindow_files_init(void)
if (git__pack_cache)
return 0;
+ git__on_shutdown(git_mwindow_files_free);
+
return git_strmap_alloc(&git__pack_cache);
}
diff --git a/src/path.c b/src/path.c
index 143c564..effe2ff 100644
--- a/src/path.c
+++ b/src/path.c
@@ -1198,7 +1198,9 @@ int git_path_dirload_with_stat(
if (error == GIT_ENOTFOUND) {
/* file was removed between readdir and lstat */
+ char *entry_path = git_vector_get(contents, i);
git_vector_remove(contents, i--);
+ git__free(entry_path);
} else {
/* Treat the file as unreadable if we get any other error */
memset(&ps->st, 0, sizeof(ps->st));
@@ -1215,8 +1217,9 @@ int git_path_dirload_with_stat(
ps->path[ps->path_len] = '\0';
}
else if (!S_ISREG(ps->st.st_mode) && !S_ISLNK(ps->st.st_mode)) {
- /* skip everything but dirs, plain files, and symlinks */
+ char *entry_path = git_vector_get(contents, i);
git_vector_remove(contents, i--);
+ git__free(entry_path);
}
}
diff --git a/src/remote.c b/src/remote.c
index 362c226..4629175 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -116,9 +116,9 @@ static int get_check_cert(int *out, git_repository *repo)
static int canonicalize_url(git_buf *out, const char *in)
{
+#ifdef GIT_WIN32
const char *c;
-#ifdef GIT_WIN32
/* Given a UNC path like \\server\path, we need to convert this
* to //server/path for compatibility with core git.
*/
@@ -1255,6 +1255,7 @@ static int opportunistic_updates(const git_remote *remote, git_vector *refs, con
error = git_reference_create(&ref, remote->repo, refname.ptr, &head->oid, true, sig, msg);
git_buf_free(&refname);
+ git_reference_free(ref);
if (error < 0)
return error;
diff --git a/src/thread-utils.h b/src/thread-utils.h
index 8deedce..dd1136c 100644
--- a/src/thread-utils.h
+++ b/src/thread-utils.h
@@ -183,8 +183,10 @@ GIT_INLINE(int64_t) git_atomic64_add(git_atomic64 *a, int64_t addend)
/* Pthreads Mutex */
#define git_mutex unsigned int
-static int git_mutex_init(git_mutex* mutex) { GIT_UNUSED(mutex); return 0; }
-static int git_mutex_lock(git_mutex* mutex) { GIT_UNUSED(mutex); return 0; }
+GIT_INLINE(int) git_mutex_init(git_mutex *mutex) \
+ { GIT_UNUSED(mutex); return 0; }
+GIT_INLINE(int) git_mutex_lock(git_mutex *mutex) \
+ { GIT_UNUSED(mutex); return 0; }
#define git_mutex_unlock(a) (void)0
#define git_mutex_free(a) (void)0
diff --git a/src/transaction.c b/src/transaction.c
index ebb943c..1a4fffb 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -274,7 +274,7 @@ static int update_target(git_refdb *db, transaction_node *node)
} else if (node->ref_type == GIT_REF_SYMBOLIC) {
ref = git_reference__alloc_symbolic(node->name, node->target.symbolic);
} else {
- assert(0);
+ abort();
}
GITERR_CHECK_ALLOC(ref);
@@ -287,7 +287,7 @@ static int update_target(git_refdb *db, transaction_node *node)
} else if (node->ref_type == GIT_REF_SYMBOLIC) {
error = git_refdb_unlock(db, node->payload, true, update_reflog, ref, node->sig, node->message);
} else {
- assert(0);
+ abort();
}
git_reference_free(ref);
@@ -300,7 +300,7 @@ int git_transaction_commit(git_transaction *tx)
{
transaction_node *node;
git_strmap_iter pos;
- int error;
+ int error = 0;
assert(tx);
diff --git a/src/transports/http.c b/src/transports/http.c
index bcfeaee..4070b68 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -552,7 +552,7 @@ static int http_connect(http_subtransport *t)
#ifdef GIT_SSL
if ((!error || error == GIT_ECERTIFICATE) && t->owner->certificate_check_cb != NULL) {
X509 *cert = SSL_get_peer_certificate(t->socket.ssl.ssl);
- git_cert_x509 cert_info;
+ git_cert_x509 cert_info, *cert_info_ptr;
int len, is_valid;
unsigned char *guard, *encoded_cert;
@@ -581,7 +581,10 @@ static int http_connect(http_subtransport *t)
cert_info.cert_type = GIT_CERT_X509;
cert_info.data = encoded_cert;
cert_info.len = len;
- error = t->owner->certificate_check_cb((git_cert *) &cert_info, is_valid, t->connection_data.host, t->owner->message_cb_payload);
+
+ cert_info_ptr = &cert_info;
+
+ error = t->owner->certificate_check_cb((git_cert *) cert_info_ptr, is_valid, t->connection_data.host, t->owner->message_cb_payload);
git__free(encoded_cert);
if (error < 0) {
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index 3868a52..1f6716f 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -457,30 +457,34 @@ static int _git_ssh_setup_conn(
LIBSSH2_SESSION* session=NULL;
LIBSSH2_CHANNEL* channel=NULL;
+ t->current_stream = NULL;
+
*stream = NULL;
if (ssh_stream_alloc(t, url, cmd, stream) < 0)
return -1;
s = (ssh_stream *)*stream;
+ s->session = NULL;
+ s->channel = NULL;
if (!git__prefixcmp(url, prefix_ssh)) {
if ((error = gitno_extract_url_parts(&host, &port, &path, &user, &pass, url, default_port)) < 0)
- goto on_error;
+ goto done;
} else {
if ((error = git_ssh_extract_url_parts(&host, &user, url)) < 0)
- goto on_error;
+ goto done;
port = git__strdup(default_port);
GITERR_CHECK_ALLOC(port);
}
if ((error = gitno_connect(&s->socket, host, port, 0)) < 0)
- goto on_error;
+ goto done;
if ((error = _git_ssh_session_create(&session, s->socket)) < 0)
- goto on_error;
+ goto done;
if (t->owner->certificate_check_cb != NULL) {
- git_cert_hostkey cert = { 0 };
+ git_cert_hostkey cert = { 0 }, *cert_ptr;
const char *key;
cert.cert_type = GIT_CERT_HOSTKEY_LIBSSH2;
@@ -499,37 +503,41 @@ static int _git_ssh_setup_conn(
if (cert.type == 0) {
giterr_set(GITERR_SSH, "unable to get the host key");
- return -1;
+ error = -1;
+ goto done;
}
/* We don't currently trust any hostkeys */
giterr_clear();
- error = t->owner->certificate_check_cb((git_cert *) &cert, 0, host, t->owner->message_cb_payload);
+
+ cert_ptr = &cert;
+
+ error = t->owner->certificate_check_cb((git_cert *) cert_ptr, 0, host, t->owner->message_cb_payload);
if (error < 0) {
if (!giterr_last())
giterr_set(GITERR_NET, "user cancelled hostkey check");
- goto on_error;
+ goto done;
}
- }
+ }
/* we need the username to ask for auth methods */
if (!user) {
if ((error = request_creds(&cred, t, NULL, GIT_CREDTYPE_USERNAME)) < 0)
- goto on_error;
+ goto done;
user = git__strdup(((git_cred_username *) cred)->username);
cred->free(cred);
cred = NULL;
if (!user)
- goto on_error;
+ goto done;
} else if (user && pass) {
if ((error = git_cred_userpass_plaintext_new(&cred, user, pass)) < 0)
- goto on_error;
+ goto done;
}
if ((error = list_auth_methods(&auth_methods, session, user)) < 0)
- goto on_error;
+ goto done;
error = GIT_EAUTH;
/* if we already have something to try */
@@ -543,25 +551,25 @@ static int _git_ssh_setup_conn(
}
if ((error = request_creds(&cred, t, user, auth_methods)) < 0)
- goto on_error;
+ goto done;
if (strcmp(user, git_cred__username(cred))) {
giterr_set(GITERR_SSH, "username does not match previous request");
error = -1;
- goto on_error;
+ goto done;
}
error = _git_ssh_authenticate_session(session, cred);
}
if (error < 0)
- goto on_error;
+ goto done;
channel = libssh2_channel_open_session(session);
if (!channel) {
error = -1;
ssh_error(session, "Failed to open SSH channel");
- goto on_error;
+ goto done;
}
libssh2_channel_set_blocking(channel, 1);
@@ -570,36 +578,25 @@ static int _git_ssh_setup_conn(
s->channel = channel;
t->current_stream = s;
- if (cred)
- cred->free(cred);
- git__free(host);
- git__free(port);
- git__free(path);
- git__free(user);
- git__free(pass);
-
- return 0;
-
-on_error:
- s->session = NULL;
- s->channel = NULL;
- t->current_stream = NULL;
+done:
+ if (error < 0) {
+ if (*stream)
+ ssh_stream_free(*stream);
- if (*stream)
- ssh_stream_free(*stream);
+ if (session)
+ libssh2_session_free(session);
+ }
if (cred)
cred->free(cred);
git__free(host);
git__free(port);
+ git__free(path);
git__free(user);
git__free(pass);
- if (session)
- libssh2_session_free(session);
-
return error;
}
diff --git a/tests/clone/local.c b/tests/clone/local.c
index fec3be5..f14b33c 100644
--- a/tests/clone/local.c
+++ b/tests/clone/local.c
@@ -26,7 +26,7 @@ static int git_style_unc_path(git_buf *buf, const char *host, const char *path)
if (path[0] == '/')
path++;
- if (isalpha(path[0]) && path[1] == ':' && path[2] == '/') {
+ if (git__isalpha(path[0]) && path[1] == ':' && path[2] == '/') {
git_buf_printf(buf, "%c$/", path[0]);
path += 3;
}
diff --git a/tests/config/snapshot.c b/tests/config/snapshot.c
index e47e252..3ea07c1 100644
--- a/tests/config/snapshot.c
+++ b/tests/config/snapshot.c
@@ -37,6 +37,7 @@ void test_config_snapshot__create_snapshot(void)
cl_git_pass(git_config_get_int32(&tmp, snapshot, "old.value"));
cl_assert_equal_i(5, tmp);
+ git_config_free(new_snapshot);
git_config_free(snapshot);
git_config_free(cfg);
}
diff --git a/tests/index/cache.c b/tests/index/cache.c
index de5cd83..3982bf1 100644
--- a/tests/index/cache.c
+++ b/tests/index/cache.c
@@ -170,6 +170,8 @@ void test_index_cache__two_levels(void)
tree_cache = git_tree_cache_get(index->tree, "subdir");
cl_assert(tree_cache);
cl_assert_equal_i(1, tree_cache->entry_count);
+
+ git_index_free(index);
}
void test_index_cache__read_tree_children(void)
diff --git a/tests/revwalk/mergebase.c b/tests/revwalk/mergebase.c
index fa974eb..aafe97d 100644
--- a/tests/revwalk/mergebase.c
+++ b/tests/revwalk/mergebase.c
@@ -171,6 +171,7 @@ void test_revwalk_mergebase__multiple_merge_bases_many_commits(void)
cl_assert_equal_oid(&expected2, &result.ids[1]);
git_oidarray_free(&result);
+ git__free(input);
}
void test_revwalk_mergebase__no_off_by_one_missing(void)
diff --git a/tests/submodule/repository_init.c b/tests/submodule/repository_init.c
index 24b47af..e9733a6 100644
--- a/tests/submodule/repository_init.c
+++ b/tests/submodule/repository_init.c
@@ -35,6 +35,7 @@ void test_submodule_repository_init__basic(void)
cl_assert(git_path_isfile("submod2/.git/modules/" "sm_gitmodules_only" "/HEAD"));
git_config_free(cfg);
+ git_submodule_free(sm);
git_repository_free(repo);
git_buf_free(&dot_git_content);
}