What steps will reproduce the problem?
1. Register a URI callback function for an existing page "a.htm" in the served
root directory by calling mg_set_uri_callback( ctx, "/a.htm", func, NULL )
2. Refresh the browser on the page "/a.htm" to see the output generated by the
callback function
3. Unregister the URI callback function for that page by calling
mg_set_uri_callback( ctx, "/a.htm", NULL, NULL )
4. Refresh the browser on the page "/a.htm"
What is the expected output? What do you see instead?
Step 4 should produce the contents of the page "a.htm" in the served root
directory. Instead, the output from the callback function is still shown, as
at step 2.
What version of the product are you using? On what operating system?
mongoose v2.8, running on Windows Vista Business, Service Pack 2
Please provide any additional information below.
I believe the problem is that ctx->num_callbacks is not decremented in the
remove_callback() function. Here is the current code starting at line 2935:
for (i = 0; i < ctx->num_callbacks; i++) {
cb = ctx->callbacks + i;
if ((uri_regex != NULL && cb->uri_regex != NULL &&
((is_auth && cb->is_auth) || (!is_auth && !cb->is_auth)) &&
!strcmp(uri_regex, cb->uri_regex)) || (uri_regex == NULL &&
(cb->status_code == 0 ||
cb->status_code == status_code))) {
(void) memmove(cb, cb + 1,
(char *) (ctx->callbacks + ctx->num_callbacks) -
(char *) (cb + 1));
break;
}
}
I believe a line to decrement ctx->num_callbacks should be added prior to the
final "break" on line 2945:
for (i = 0; i < ctx->num_callbacks; i++) {
cb = ctx->callbacks + i;
if ((uri_regex != NULL && cb->uri_regex != NULL &&
((is_auth && cb->is_auth) || (!is_auth && !cb->is_auth)) &&
!strcmp(uri_regex, cb->uri_regex)) || (uri_regex == NULL &&
(cb->status_code == 0 ||
cb->status_code == status_code))) {
(void) memmove(cb, cb + 1,
(char *) (ctx->callbacks + ctx->num_callbacks) -
(char *) (cb + 1));
ctx->num_callbacks--;
break;
}
}
(Note also that there is a memory leak in this function, which I'll raise as a
separate issue.)
Original issue reported on code.google.com by AdrianLo...@comcast.net on 11 Jun 2010 at 1:53
Original issue reported on code.google.com by
AdrianLo...@comcast.net
on 11 Jun 2010 at 1:53