Fossil SCM

Eliminate a superfluous allocation and have freepass() zero out its storage to avoid a duplicate free() in the very off chance that it's ever called twice. These are cleanups made in passing, not fixing known problems.

stephan 2025-08-03 11:31 trunk
Commit 1c9d5cd81dd0531e146e18147644766e93ddad88ea6427371c29ec710874cd24
1 file changed +4 -3
+4 -3
--- src/user.c
+++ src/user.c
@@ -109,10 +109,12 @@
109109
}
110110
void freepass(){
111111
if( !zPwdBuffer ) return;
112112
assert( nPwdBuffer>0 );
113113
fossil_secure_free_page(zPwdBuffer, nPwdBuffer);
114
+ zPwdBuffer = 0;
115
+ nPwdBuffer = 0;
114116
}
115117
#endif
116118
117119
/*
118120
** Scramble substitution matrix:
@@ -286,13 +288,12 @@
286288
char *zPrompt = mprintf("\rpassword for %s: ", zUser);
287289
char *zPw;
288290
Blob x;
289291
fossil_force_newline();
290292
prompt_for_password(zPrompt, &x, 0);
291
- free(zPrompt);
292
- zPw = mprintf("%b", &x);
293
- blob_reset(&x);
293
+ fossil_free(zPrompt);
294
+ zPw = blob_str(&x)/*transfer ownership*/;
294295
return zPw;
295296
}
296297
297298
/*
298299
** Prompt the user to enter a single line of text.
299300
--- src/user.c
+++ src/user.c
@@ -109,10 +109,12 @@
109 }
110 void freepass(){
111 if( !zPwdBuffer ) return;
112 assert( nPwdBuffer>0 );
113 fossil_secure_free_page(zPwdBuffer, nPwdBuffer);
 
 
114 }
115 #endif
116
117 /*
118 ** Scramble substitution matrix:
@@ -286,13 +288,12 @@
286 char *zPrompt = mprintf("\rpassword for %s: ", zUser);
287 char *zPw;
288 Blob x;
289 fossil_force_newline();
290 prompt_for_password(zPrompt, &x, 0);
291 free(zPrompt);
292 zPw = mprintf("%b", &x);
293 blob_reset(&x);
294 return zPw;
295 }
296
297 /*
298 ** Prompt the user to enter a single line of text.
299
--- src/user.c
+++ src/user.c
@@ -109,10 +109,12 @@
109 }
110 void freepass(){
111 if( !zPwdBuffer ) return;
112 assert( nPwdBuffer>0 );
113 fossil_secure_free_page(zPwdBuffer, nPwdBuffer);
114 zPwdBuffer = 0;
115 nPwdBuffer = 0;
116 }
117 #endif
118
119 /*
120 ** Scramble substitution matrix:
@@ -286,13 +288,12 @@
288 char *zPrompt = mprintf("\rpassword for %s: ", zUser);
289 char *zPw;
290 Blob x;
291 fossil_force_newline();
292 prompt_for_password(zPrompt, &x, 0);
293 fossil_free(zPrompt);
294 zPw = blob_str(&x)/*transfer ownership*/;
 
295 return zPw;
296 }
297
298 /*
299 ** Prompt the user to enter a single line of text.
300

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button