Commit 8ded5cca authored by Pekka Pessi's avatar Pekka Pessi

Fixed allocation code for message parser table.

Allocating parser table as a single memory block.

darcs-hash:20051102152942-65a35-02bec298145f5b4ea50718dc634da34e190431ba.gz
parent 8fc0f473
......@@ -30,7 +30,7 @@
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
*
* @date Created: Wed Jun 5 14:34:24 2002 ppessi
* @date Last modified: Fri Sep 9 10:56:31 2005 ppessi
* @date Last modified: Wed Nov 2 12:03:56 2005 ppessi
*/
#include "config.h"
......@@ -72,6 +72,7 @@
* @return
* The function msg_mclass_clone() returns a pointer to a newly
* copied message class object, or NULL upon an error.
* The returned message class object can be freed with free().
*
* @ERRORS
* @ERROR ENOMEM
......@@ -89,7 +90,7 @@
*/
msg_mclass_t *msg_mclass_clone(msg_mclass_t const *old, int newsize, int empty)
{
size_t size;
size_t size, shortsize;
msg_mclass_t *mc;
int identical;
unsigned short i;
......@@ -103,7 +104,11 @@ msg_mclass_t *msg_mclass_clone(msg_mclass_t const *old, int newsize, int empty)
}
size = offsetof(msg_mclass_t, mc_hash[newsize]);
mc = malloc(size);
if (old->mc_short)
shortsize = MC_SHORT_SIZE * (sizeof old->mc_short[0]);
else
shortsize = 0;
mc = malloc(size + shortsize);
identical = newsize == old->mc_hash_size && !empty;
if (mc) {
......@@ -122,16 +127,11 @@ msg_mclass_t *msg_mclass_clone(msg_mclass_t const *old, int newsize, int empty)
mc->mc_short = NULL;
}
if (old->mc_short) {
msg_href_t *shorts = calloc(MC_SHORT_SIZE, sizeof shorts[0]);
if (shorts) {
mc->mc_short = shorts;
if (!empty)
memcpy(shorts, old->mc_short, MC_SHORT_SIZE * sizeof shorts[0]);
}
if (shortsize) {
if (empty)
mc->mc_short = memset((char *)mc + size, 0, shortsize);
else
free(mc), mc = NULL;
mc->mc_short = memcpy((char *)mc + size, old->mc_short, shortsize);
}
}
......
......@@ -46,7 +46,6 @@ struct sres_context_s;
#define _XOPEN_SOURCE (500)
#include <stdint.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <poll.h>
......@@ -63,6 +62,8 @@ struct sres_context_s;
#include <string.h>
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <su_alloc.h>
#if HAVE_ALARM
......@@ -1853,7 +1854,7 @@ int main(int argc, char **argv)
{
int i;
int error = 0;
int o_alarm = 1;
int o_attach = 0, o_alarm = 1;
sres_context_t ctx[1] = {{{SU_HOME_INIT(ctx)}}};
for (i = 1; argv[i]; i++) {
......@@ -1867,6 +1868,9 @@ int main(int argc, char **argv)
else if (strcmp(argv[i], "--no-alarm") == 0) {
o_alarm = 0;
}
else if (strcmp(argv[i], "--attach") == 0) {
o_attach = 1;
}
else if (strncmp(argv[i], "-l", 2) == 0) {
int level = 3;
char *rest = NULL;
......@@ -1888,8 +1892,16 @@ int main(int argc, char **argv)
su_init();
if (o_attach) {
char buf[8];
fprintf(stderr, "test_sresolv: started with pid %u"
" (press enter to continue)\n", getpid());
fgets(buf, sizeof buf, stdin);
}
#if HAVE_ALARM
if (o_alarm) {
else if (o_alarm) {
alarm(60);
signal(SIGALRM, sig_alarm);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment