Thread (59 messages) 59 messages, 4 authors, 2022-08-16

Re: [PATCH v1 3/7] mv: free the *with_slash in check_dir_in_index()

From: Derrick Stolee <hidden>
Date: 2022-07-19 17:46:50

On 7/19/2022 9:28 AM, Shaoxuan Yuan wrote:> *with_slash may be a malloc'd pointer, and when it is, free it.
It might be worth mentioning that you are reorganizing the
method to use gotos.
 static int check_dir_in_index(const char *name)
 {
+	int ret = 1;
Interesting to "assume error", but that works since there is only one
place where the success is guaranteed.

Should we use -1 here?
 		if (ce_skip_worktree(ce))
-			return 0;
+			ret = 0;
This could be

	ret = ce_skip_worktree(ce);

unless you really rely on the "1" value.
 	}
-	return 1;
+
+free_return:
+	if (with_slash != name)
+		free((char *)with_slash);
Good check to not clear 'name'. It's unfortunate that we need to cast here,
but it makes sense.

Thanks,
-Stolee
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help