From 8ef12d52f638175b35e9845f5bb3d9d95005e055 Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Thu, 22 Apr 2004 04:20:30 +0000 Subject: [PATCH] Fix for out of stack space on large music libraries --- src/daap-proto.c | 65 ++++++++++++++++++++++++------------------------ src/main.c | 7 ++++-- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/daap-proto.c b/src/daap-proto.c index 7d5c6949..0dd107c3 100644 --- a/src/daap-proto.c +++ b/src/daap-proto.c @@ -239,33 +239,31 @@ DAAP_BLOCK *daap_add_empty(DAAP_BLOCK *parent, char *tag) { int daap_serialize(DAAP_BLOCK *root, int fd, int gzip) { char size[4]; - if(!root) - return 0; + while(root) { + r_write(fd,root->tag,4); + + size[0] = (root->reported_size >> 24) & 0xFF; + size[1] = (root->reported_size >> 16) & 0xFF; + size[2] = (root->reported_size >> 8 ) & 0xFF; + size[3] = (root->reported_size) & 0xFF; + + r_write(fd,&size,4); + + if(root->size) { + if(root->free) + r_write(fd,root->value,root->size); + else + r_write(fd,root->svalue,root->size); + } - r_write(fd,root->tag,4); + if(root->children) { + if(daap_serialize(root->children,fd,gzip)) + return -1; + } - size[0] = (root->reported_size >> 24) & 0xFF; - size[1] = (root->reported_size >> 16) & 0xFF; - size[2] = (root->reported_size >> 8 ) & 0xFF; - size[3] = (root->reported_size) & 0xFF; - - r_write(fd,&size,4); - - if(root->size) { - if(root->free) - r_write(fd,root->value,root->size); - else - r_write(fd,root->svalue,root->size); + root=root->next; } - if(root->children) { - if(daap_serialize(root->children,fd,gzip)) - return -1; - } - - if(daap_serialize(root->next,fd,gzip)) - return -1; - return 0; } @@ -275,17 +273,20 @@ int daap_serialize(DAAP_BLOCK *root, int fd, int gzip) { * Free an entire daap formatted block */ void daap_free(DAAP_BLOCK *root) { - if(!root) - return; + DAAP_BLOCK *pnext; - DPRINTF(ERR_DEBUG,"Freeing %c%c%c%c\n",root->tag[0],root->tag[1], - root->tag[2],root->tag[3]); + while(root) { + DPRINTF(ERR_DEBUG,"Freeing %c%c%c%c\n",root->tag[0],root->tag[1], + root->tag[2],root->tag[3]); - if((root->size) && (root->free)) - free(root->value); /* otherwise, static value */ + if((root->size) && (root->free)) + free(root->value); /* otherwise, static value */ - daap_free(root->children); - daap_free(root->next); - free(root); + daap_free(root->children); + + pnext=root->next; + free(root); + root=pnext; + } return; } diff --git a/src/main.c b/src/main.c index 66836976..abc90680 100644 --- a/src/main.c +++ b/src/main.c @@ -457,7 +457,7 @@ void *signal_handler(void *arg) { /* process the signal */ switch(sig) { case SIGINT: - DPRINTF(ERR_LOG,"Got INT signal. Notifying daap server.\n"); + DPRINTF(ERR_LOG,"Got INT signal. Notifying daap server.\n"); config.stop=1; return NULL; break; @@ -465,6 +465,9 @@ void *signal_handler(void *arg) { DPRINTF(ERR_LOG,"Got HUP signal. Notifying daap server.\n"); config.reload=1; break; + default: + DPRINTF(ERR_LOG,"What am I doing here?\n"); + break; } } } @@ -649,7 +652,7 @@ int main(int argc, char *argv[]) { config.reload=0; DPRINTF(ERR_LOG,"Reloading configuration\n"); } - sleep(10); + sleep(2); } DPRINTF(ERR_LOG,"Stopping gracefully\n");