threads / patch / 17236

patchhttp-push: update memory allocation for http headers

Subject: [PATCH] http-push: update memory allocation for http headers

## tl;dr

3 messages between Jan 18, 2009 and Jan 18, 2009. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Ray Chuan· Jan 18, 2009, 13:16 UTC · lore

In 753bc91 (Remove the requirement opaquelocktoken uri scheme), the header strings were with the removal "opaquelocktoken:" (16 characters).

Unfortunately, this was without the corresponding change in memory allocation. In this patch we update these allocations.

Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
 http-push.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
Show changes to http-push.c +4 −4
diff --git a/http-push.c b/http-push.c
index a4b7d08..a6522dd 100644
--- a/http-push.c
+++ b/http-push.c
@@ -595,7 +595,7 @@ static int refresh_lock(struct remote_lock *lock)

 	lock->refreshing = 1;

-	if_header = xmalloc(strlen(lock->token) + 25);
+	if_header = xmalloc(strlen(lock->token) + 9);
 	sprintf(if_header, "If: (<%s>)", lock->token);
 	sprintf(timeout_header, "Timeout: Second-%ld", lock->timeout);
 	dav_headers = curl_slist_append(dav_headers, if_header);
@@ -1306,7 +1306,7 @@ static int unlock_remote(struct remote_lock *lock)
 	struct curl_slist *dav_headers = NULL;
 	int rc = 0;

-	lock_token_header = xmalloc(strlen(lock->token) + 31);
+	lock_token_header = xmalloc(strlen(lock->token) + 15);
 	sprintf(lock_token_header, "Lock-Token: <%s>",
 		lock->token);
 	dav_headers = curl_slist_append(dav_headers, lock_token_header);
@@ -1730,7 +1730,7 @@ static int update_remote(unsigned char *sha1,
struct remote_lock *lock)
 	struct buffer out_buffer = { STRBUF_INIT, 0 };
 	struct curl_slist *dav_headers = NULL;

-	if_header = xmalloc(strlen(lock->token) + 25);
+	if_header = xmalloc(strlen(lock->token) + 9);
 	sprintf(if_header, "If: (<%s>)", lock->token);
 	dav_headers = curl_slist_append(dav_headers, if_header);

@@ -1949,7 +1949,7 @@ static void update_remote_info_refs(struct
remote_lock *lock)
 	remote_ls("refs/", (PROCESS_FILES | RECURSIVE),
 		  add_remote_info_ref, &buffer.buf);
 	if (!aborted) {
-		if_header = xmalloc(strlen(lock->token) + 25);
+		if_header = xmalloc(strlen(lock->token) + 9);
 		sprintf(if_header, "If: (<%s>)", lock->token);
 		dav_headers = curl_slist_append(dav_headers, if_header);
-- 
1.6.0.4
Mike Hommey· Jan 18, 2009, 14:20 UTC · re: Ray Chuan · lore

Re: [PATCH] http-push: update memory allocation for http headers

On Sun, Jan 18, 2009 at 09:16:04PM +0800, Ray Chuan wrote:
Show 9 quoted lines
> In 753bc91 (Remove the requirement opaquelocktoken uri scheme), the
> header strings were with the removal "opaquelocktoken:" (16
> characters).
> 
> Unfortunately, this was without the corresponding change in memory
> allocation. In this patch we update these allocations.
> 
> Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
> ---

It would be better to just turn the whole thing to use strbuf, and/or extend the patch set I sent earlier today to handle webdav.

Mike
Johannes Schindelin· Jan 18, 2009, 14:55 UTC · re: Ray Chuan · lore

Re: [PATCH] http-push: update memory allocation for http headers

Hi,
On Sun, 18 Jan 2009, Ray Chuan wrote:
Show 6 quoted lines
> In 753bc91 (Remove the requirement opaquelocktoken uri scheme), the
> header strings were with the removal "opaquelocktoken:" (16
> characters).
> 
> Unfortunately, this was without the corresponding change in memory
> allocation. In this patch we update these allocations.

Rather than doing this (which will result in as error-prone code), why don't you replace those things by strbufs?

Ciao, Dscho

← back to recent threads